Hey i created a new project with latest angular cli. It creates a project that uses jasmine as the testing framework. I wanted to use mocha.
I added the required plugins following the project https://github.com/arranbartish/angular-cli-seed/blob/master/karma.conf.js
I get the following error when running test using command ng test
Has anybody faced an error or is there a way to figure out what is generating this issue.
The Problem
zone.js
uses a handful of "patches" when it is used in a test environment. For convenience,zone.js
provides a single module that bundles all those patches together. That module iszone.js/dist/zone-testing
. This is the package that@angular/cli
uses in the test setup, it is imported insrc/test.ts
. The problem is thatzone.js/dist/zone-testing
assumes you are using jasmine and includes a jasmine patch. The jasmine patch is what is causing your error.The Fix
To fix it, you just have to import each of the patches yourself instead of using the convenience, prepackaged module. In
src/test.ts
needs to become
These are the exact same packages that
zone.js/dist/zone-testing
uses; however, it is importing themocha-patch
instead of thejasmine-patch
.