angular: RC6 unit tests with mocha fail to run
I’m submitting a … (check one with “x”)
[*] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
No tests run. It was working fine in RC5 and all breaking changes have been addressed. The error given is:
Expected to be running in 'ProxyZone', but it was not found.
assertPresent@test.ts:6620:98
resetFakeAsyncZone@test.ts:25346:37
test.ts:26216:32
This is thrown before the it
block is executed. Switching from mocha to jasmine + adding the zone jasmine patch fixes the issue as a workaround.
Expected/desired behavior Tests should run with mocha
Reproduction of the problem
I’ve put together a repo which reproduces the error here: https://github.com/mattlewis92/angular2-testing-bug/blob/master/test.ts
What is the motivation / use case for changing the behavior?
N/A
Please tell us about your environment:
- Angular version: 2.0.0-rc.6
- Browser: [PhantomJS 2]
- Language: [TypeScript 1.8]
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 5
- Comments: 49 (23 by maintainers)
We’ll be cutting a release of zone.js within the next few days. Once that happens you’ll be able to get the patch from the npm package then.
On Wed, Nov 16, 2016 at 9:55 AM nording notifications@github.com wrote:
There is a Mocha-patch available, https://github.com/angular/zone.js/tree/master/lib/mocha, it works well with the test utils like async and fakeAsync.
Doing the following after calling
TestBed.initTestEnvironment
is also a viable workaround if one doesn’t useasync
orfakeAsync
:No. Even when I use only
describe
andit
, it fails.Then I added
import 'zone.js/dist/proxy';
, but it still failed.Also,
import 'zone.js/dist/sync-test';
didn’t solve anything.The problem we should solve is that A2 is depending on a specific testing framework by the default.
I already did that: https://github.com/mattlewis92/angular2-testing-bug/blob/master/test.ts#L7
My imports in my spec-bundle.js file look like this and work fine:
As this is currently the first google result for “Expected to be running in ‘ProxyZone’, but it was not found”, I’ll offer a solution unrelated to the report above.
I stupidly had my
fakeAsync()
call around thedescribe
callback block instead of theit
callback. Took me a little head scratching to figure it out, so maybe this will save others some time.I got it working somehow using “interfaces” extension feature of Mocha. Refer to this gist for details.
It’s a quick initial try with some missing bits, but it works with my tests. The biggest missing part is a counterpart to jasmine QueueRunner patching. Once I figure out how to deal with it, I will put this to an npm module, I guess.
Hey, @HichamBI I’m using mocha with jsdom without any issues. Though I don’t use the “official” patch, but rather my own – see my earlier comment in this thread.
I also copy properties from jsdom’s window to global and set global.window – everything before requiring zone.js and company.
Hope this helps.
@laco0416, I’m writing mocha test for a small library and don’t need
async
orfakeAsync
so I skip the wholeTestBed.initTestEnvironment
which works fine.@juliemr What do you think about this?
No, I don’t want to use karma and phantomjs if it possible. I want also understand why it not working with the new Zone.js release.
Confirmed that the latest zone.js version mocha patch works perfectly, nice work @nording !