Repository navigation
Closed
Description
I've followed the instructions, but when I execute npm run test, I'm receiving the following error:
> starter-with-testing@0.0.1 test-ci /home/jmgomez/securitas/test/starter-with-testing
> karma start ./test-config/karma.conf.js --single-run
webpack: Compiled successfully.
webpack: Compiling...
webpack: Compiled with warnings.
16 02 2018 15:24:04.909:INFO [karma]: Karma v2.0.0 server started at http://0.0.0.0:9876/
16 02 2018 15:24:04.910:INFO [launcher]: Launching browser Chrome with unlimited concurrency
16 02 2018 15:24:04.931:INFO [launcher]: Starting browser Chrome
16 02 2018 15:24:05.989:INFO [Chrome 64.0.3282 (Linux 0.0.0)]: Connected on socket 6K6qqAOzO0RIRsN8AAAA with id 89855277
Chrome 64.0.3282 (Linux 0.0.0) ERROR
{
"message": "An error was thrown in afterAll\nUncaught TypeError: env.catchExceptions is not a function",
"str": "An error was thrown in afterAll\nUncaught TypeError: env.catchExceptions is not a function"
}
Chrome 64.0.3282 (Linux 0.0.0) ERROR
{
"message": "An error was thrown in afterAll\nUncaught TypeError: env.catchExceptions is not a function",
"str": "An error was thrown in afterAll\nUncaught TypeError: env.catchExceptions is not a function"
}
Chrome 64.0.3282 (Linux 0.0.0): Executed 0 of 0 ERROR (0.004 secs / 0 secs)
Chrome 64.0.3282 (Linux 0.0.0): Executed 0 of 0 ERROR (0.016 secs / 0 secs)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! starter-with-testing@0.0.1 test-ci: `karma start ./test-config/karma.conf.js --single-run`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the starter-with-testing@0.0.1 test-ci script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/jmgomez/.npm/_logs/2018-02-16T14_24_06_588Z-debug.log
Result for ionic info is the following one:
cli packages: (/home/jmgomez/.nvm/versions/node/v8.9.1/lib/node_modules)
@ionic/cli-utils : 1.19.1
ionic (Ionic CLI) : 3.19.1
local packages:
@ionic/app-scripts : 3.1.8
Ionic Framework : ionic-angular 3.9.2
System:
Node : v8.9.1
npm : 5.6.0
OS : Linux 4.4
Misc:
backend : pro
My android version is 5 instead of 4 as you can check in the package.json uploaded in the repository https://github.com/biaggi/karma-test-failing. Any hint on what's happening there?
Reacted by Serkan Holat, KimHyungRyuk, sol, Stan Kurdziel, Greg Trevellick, Mateusz Danieluk, Saucistophe, Diego Flores and Denes Papp
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
No fields configured for issues without a type.
Activity
varghese-dev commentedon Feb 18, 2018
@biaggi I was getting similar error and downgrading the jasmine to 2.99 version solved the issue for me.
"jasmine": "2.99".
Try it.
biaggi commentedon Feb 19, 2018
@varnit-abraham Thank you for your help, but seems that the problem is a different one, the npm list it's already reporting that jasmine's version is 2.99
devinshoemaker commentedon Feb 24, 2018
Thank you @varnit-abraham that seems to have fixed my issues, but do you know why this was causing issues? There must be some breaking change with Jasmine 3.0.0 but I'm not sure what library it's conflicting with.
anibalsanchez commentedon Feb 27, 2018
Same issue here, and the version downgrade also solved the case:
biaggi commentedon Feb 27, 2018
You are right... there must be some sort of dependency there that depends directly from jasmine@2.99.0
It works installing such package. Thank you all and I'm sorry for not trying it before
igcarun07 commentedon Mar 2, 2018
@biaggi after install jasmine@2.99.0 it show cannot read property has undefined. Thanks in advance
hyungryuk-zz commentedon Mar 8, 2018
@biaggi i solved it!! after install jasmine@2.99.0, install jasmine-core@^2.99.0 as well! try it
"jasmine": "^2.99.0",
"jasmine-core": "^2.99.0",
ChrisGibb commentedon Mar 13, 2018
Looks like might be a problem with karma-jasmine-html-reporter
Reverting back fixes the issue
jackrvaughan commentedon Mar 30, 2018
"jasmine": "^2.99.0",
"jasmine-core": "^2.99.0"
Doesn't seem to fix it for me :/
leifwells commentedon Mar 30, 2018
@jackrvaughan Make sure you downgrade your
ts-loaderto3.5.0.Take a look at my PR here: (https://github.com/ionic-team/ionic-unit-testing-example/pull/87)[https://github.com/ionic-team/ionic-unit-testing-example/pull/87]
jackrvaughan commentedon Apr 2, 2018
EDIT: I had an unrelated issue (one of my tests was broken) that was throwing this same error. Sorry!
Thanks for the reply @leifwells !
I just noticed that this was an ionic specific thread. I don't use ionic, webpack, or ts-loader; but am hitting this issue all the same.
jdnav commentedon Feb 5, 2019
I was facing the same error.
This combination worked for me in v7:
./package.json
Good luck!
vipinsingh01992 commentedon Aug 31, 2019
Facing this issue after doing all:
An error was thrown in afterAll
Uncaught TypeError: Cannot read property 'toLowerCase' of undefined thrown
AshuSingh07 commentedon Mar 18, 2020
I added ts-loader:3.5.0 and typescript: 2.8.4 and it worked for me in Angular 5, ionic 3, Karma 1.71 and jasmine2.99.0 :
"devDependencies": {
"@babel/register": "7.8.3",
"@ionic/app-scripts": "^3.2.3",
"@types/crypto-js": "3.1.43",
"@types/es6-promise": "3.3.0",
"@types/jasmine": "^2.8.6",
"@types/node": "8.10.45",
"@types/request-promise": "4.1.45",
"angular2-template-loader": "0.6.2",
"es6-template-strings": "2.0.1",
"html-loader": "0.5.5",
"ionic-mocks": "1.3.0",
"istanbul-instrumenter-loader": "3.0.1",
"jasmine": "2.99.0",
"jasmine-core": "^2.99.0",
"jasmine-spec-reporter": "4.2.1",
"karma": "1.7.1",
"karma-chrome-launcher": "2.2.0",
"karma-coverage-istanbul-reporter": "1.4.3",
"karma-firefox-launcher": "^1.3.0",
"karma-jasmine": "1.1.2",
"karma-jasmine-html-reporter": "0.2.2",
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "0.0.32",
"karma-webpack": "2.0.13",
"ts-loader": "^3.5.0",
"typescript": "^2.8.4"
},
Atul-Lohiya commentedon Jan 6, 2022
Seems like angular/karma/jasmine still have this issue. I was using angular 10, jasmine 3.6, karma 5 and still ran into this issue. I did not write the afterAll anywhere and yet this was failing. The reason was async operations that were returning Observable.
Fix was to pass "done" function parameter to all test cases which were expecting aboe async behaviour and calling "done()" at the end of it something like below.
it('should not get any data', (done) => { SetupMockActivatedRoute_ParamMap(id, "someParamValue"); SetupDataFetcherService_GetData(id, someOtherParam); component.ngOnInit(); expect(component.data).toBeFalsy(); done(); });Here, ngOnInit makes ajax call to get some data. Above test case expects to not get any data and instead show some message to user hence the falsy assertion. I had to to this in all of my test cases where Observable was being used.
Additionally, there were alot of default generated tests that were not taking care of this. So I cleaned up those to either remove them or fix them like above. And then I fixed all other such cases and now it works everytime in my CICD pipeline.
So in general if you are getting this error, chances are some mocking is not right or you are not using done() function.
Also, for reference, read @FDIM's comments at https://github.com/angular/angular/issues/33800.