Closed biaggi closed 6 years ago
@biaggi I was getting similar error and downgrading the jasmine to 2.99 version solved the issue for me. "jasmine": "2.99".
Try it.
@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
npm list
...
├─┬ jasmine@2.99.0
│ ├── exit@0.1.2
│ ├── glob@7.1.2 deduped
│ └── jasmine-core@2.99.1
...
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.
Same issue here, and the version downgrade also solved the case:
npm install --save-dev jasmine@^2.99.0
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
@biaggi after install jasmine@2.99.0 it show cannot read property has undefined. Thanks in advance
@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",
Looks like might be a problem with karma-jasmine-html-reporter
{
"message": "Uncaught TypeError: env.catchExceptions is not a function\nat node_modules/karma-jasmine-html-reporter/src/lib/adapter.js:24:9\n\nTypeError: env.catchExceptions is not a function\n at node_modules/karma-jasmine-html-reporter/src/lib/adapter.js:24:9\n at node_modules/karma-jasmine-html-reporter/src/lib/adapter.js:58:3",
"str": "Uncaught TypeError: env.catchExceptions is not a function\nat node_modules/karma-jasmine-html-reporter/src/lib/adapter.js:24:9\n\nTypeError: env.catchExceptions is not a function\n at node_modules/karma-jasmine-html-reporter/src/lib/adapter.js:24:9\n at node_modules/karma-jasmine-html-reporter/src/lib/adapter.js:58:3"
}
npm ls --depth=0 | grep jasmine
├── @types/jasmine@2.8.6
├── @types/jasminewd2@2.0.3
├── jasmine-core@3.1.0
├── jasmine-spec-reporter@4.2.1
├── karma-jasmine@1.0.2
├── karma-jasmine-diff-reporter@1.1.1
├── karma-jasmine-html-reporter@0.2.2
Reverting back fixes the issue
npm install karma@^2.99
npm install jasmine-core@^2.99
"jasmine": "^2.99.0", "jasmine-core": "^2.99.0"
Doesn't seem to fix it for me :/
@jackrvaughan Make sure you downgrade your ts-loader
to 3.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]
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.
"dependencies": {
"@angular/animations": "^5.1.0",
"@angular/common": "^5.1.0",
"@angular/compiler": "^5.1.0",
"@angular/core": "^5.1.0",
"@angular/forms": "^5.1.0",
"@angular/http": "^5.1.0",
"@angular/platform-browser": "^5.1.0",
"@angular/platform-browser-dynamic": "^5.1.0",
"@angular/router": "^5.1.0",
"core-js": "^2.4.1",
"raven-js": "^3.22.3",
"rxjs": "^5.5.6",
"zone.js": "^0.8.19"
},
"devDependencies": {
"@angular/cli": "^1.7.3",
"@angular/compiler-cli": "^5.1.0",
"@angular/language-service": "^5.1.0",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "~4.0.1",
"jasmine": "^2.99.0",
"jasmine-core": "^2.99.0",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.3.3",
"karma-jasmine": "^1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "^2.5.3"
}
I was facing the same error. This combination worked for me in v7:
./package.json
{
...
"dependencies": {
"@angular/animations": "~7.0.0",
"@angular/common": "~7.0.0",
"@angular/compiler": "~7.0.0",
"@angular/core": "~7.0.0",
"@angular/forms": "~7.0.0",
"@angular/http": "~7.0.0",
"@angular/platform-browser": "~7.0.0",
"@angular/platform-browser-dynamic": "~7.0.0",
"@angular/router": "~7.0.0",
"core-js": "^2.5.4",
"rxjs": "~6.3.3",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.10.0",
"@angular/cli": "~7.0.4",
"@angular/compiler-cli": "~7.0.0",
"@angular/language-service": "~7.0.0",
"@types/node": "~8.9.4",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~3.1.1"
}
}
Good luck!
Facing this issue after doing all: An error was thrown in afterAll Uncaught TypeError: Cannot read property 'toLowerCase' of undefined thrown
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" },
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.
I've followed the instructions, but when I execute npm run test, I'm receiving the following error:
Result for ionic info is the following one:
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?