Ionic Jasmine : env.stopOnSpecFailure is not a fun

2020-07-03 04:10发布

问题:

Using Ionic with jasmine-karma, while run test, getting success compile but in jasmine dashboard getting empty screen with error in console.

Following tutorial : https://leifwells.github.io/2017/08/27/testing-in-ionic-configure-existing-projects-for-testing/

"ts-loader": "^4.1.0",
"jasmine-core": "^2.99.1"

Error Messages :

TypeError: env.stopOnSpecFailure is not a function at adapter.js:26

Error: Module build failed: TypeError: Cannot read property 'afterCompile' of undefined

回答1:

The failure occurs in your version of karma-jasmine which tries to use the stopOnSpecFailure function. That function is not present in your version of jasmine-core, you'll need version 3 or greater. Version 3.1.0 is the newest right now and works good. Also note that if you're using Webpack 3 you should also downgrade ts-loader to 3.5.0.

UPDATE:

I noticed that many people suggests downgrading jasmine-core to 2.99.1. Apparently people have problems using jasmine-core 3. If that's the case for you, then you can use karma-jasmine-html-reporter version 0.2.2 together with jasmine-core 2.99.1.