Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Jasmine 3.0.0 breaks Angular 5.2 tests #1015

Closed
rnadler opened this issue Feb 7, 2018 · 58 comments
Closed

Jasmine 3.0.0 breaks Angular 5.2 tests #1015

rnadler opened this issue Feb 7, 2018 · 58 comments

Comments

@rnadler
Copy link

rnadler commented Feb 7, 2018

Duplicated from: jasmine/jasmine#1496

Expected Behavior

Tests work with Jasmine 2.9.1

Current Behavior

With Jasmine 3.0.0, all tests fail with this error:

TypeError: Cannot read property 'run' of null
  at <Jasmine>
  at UserContext.<anonymous> home/bobn/Projects/app/node_modules/zone.js/dist/jasmine-patch.js:106:1)
  at <Jasmine>
  at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask home/bobn/Projects/app/node_modules/zone.js/dist/zone.js:421:1)
  at Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask home/bobn/Projects/app/node_modules/zone.js/dist/zone.js:188:1)
  at drainMicroTaskQueue home/bobn/Projects/app/node_modules/zone.js/dist/zone.js:595:1)
  at <Jasmine>

Same behavior using Angular 5.2.3 and 5.2.4.
It seems as though jasmine-patch.js is no longer compatible with Jasmine 3.0.0.

Your Environment

Ubuntu 16.04
Chrome 64.0.3282 (Linux)
package.json: "zone.js": "^0.8.20"
ng -v

Angular CLI: 1.6.7
Node: 8.8.1
OS: linux x64
Angular: 5.2.4
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.6.7
@angular-devkit/build-optimizer: 0.0.42
@angular-devkit/core: 0.0.29
@angular-devkit/schematics: 0.0.52
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.7
@schematics/angular: 0.1.17
typescript: 2.7.1
webpack: 3.10.0

@pe8ter
Copy link

pe8ter commented Feb 7, 2018

The variable testProxyZone in jasmine-patch.js is unexpectedly null.

@JiaLiPassion
Copy link
Collaborator

I will check it, thank you!

@JiaLiPassion
Copy link
Collaborator

@rnadler , I have found the reason and will provide a PR soon.

JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Feb 9, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Feb 9, 2018
@dfederm
Copy link

dfederm commented Feb 9, 2018

@JiaLiPassion I just tried your changes and they mostly work. My tests which don't use a done callback, fakeasync or async seem to not properly report their status (they run but they don't count as "ran", "failed" or "skipped"). To be fair, I'm not sure if that's a zone.js thing or something with jasmine, karma-jasmine, or the reporter I'm using.

@JiaLiPassion
Copy link
Collaborator

@dfederm , could you post a reproduce repo? I haven't tried with angular, I am still making this PR working in zone.js repo.

@dfederm
Copy link

dfederm commented Feb 9, 2018

@JiaLiPassion looks like it's throwing here:
image

Zone.current is a ProxyZone whose parent is the ambientZone ("<root>").

The repro is actually really simple:

    it("works as expected", (done) => {
        expect(0).toBe(0);
        done();
    });

    it("does not work", () => {
        expect(0).toBe(0);
    });

PS. I'm not very versed in zone.js, so please excuse any naivete on my part.

@JiaLiPassion
Copy link
Collaborator

@dfederm , ok , thank you for the debug information, I will check it.

JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Feb 9, 2018
@dfederm
Copy link

dfederm commented Feb 9, 2018

@JiaLiPassion so I started deleting more and more code to help narrow it down and realized I lied a little. My tests actually have a beforeEach which does something like...

    beforeEach(done => {
        TestBed.configureTestingModule({ ... })
            .compileComponents()
            .then(() => {
                fixture = TestBed.createComponent(...);
            })
            .then(done)
            .catch(done.fail);
    });

If I remove that, it seems to work. So it seems like something goes awry if I do something angular-ish and async in the beforeEach but then the test is fully synchronous.

Also, this doesn't solve the problem, but in jasmine-patch.js if I replace

throw new Error('Unexpected Zone: ' + Zone.current.name);

with

this.fail(new Error('Unexpected Zone: ' + Zone.current.name));

I get a real failure instead of the test being excluded silently.

@dfederm
Copy link

dfederm commented Feb 9, 2018

@JiaLiPassion I just tried your latest changes that handles child zones and my tests now pass! Assuming that's the "right" fix and not a temp hack you were just playing with.

@JiaLiPassion
Copy link
Collaborator

@dfederm , thank you for quick confirm, yes, check child zone is the right fix, I will do some other test to make sure it work with async and fakeAsync.

@proustibat
Copy link

Don't know if it can help but I have the same issue with the version 3.0.0:
TypeError: null is not an object (evaluating 'testProxyZone.run')

All logs are visible on the pull request that tries to update Jasmine here:
https://travis-ci.org/proustibat/fbrgsmn.mobile.app/builds/338193121

Indeed I also have a beforeEach with async in my tests

@JiaLiPassion
Copy link
Collaborator

@proustibat , the null issue have been fixed, I will do more test, thank you.

@dfederm
Copy link

dfederm commented Feb 12, 2018

@JiaLiPassion I'm not meaning to badger you but was wondering what the status was on a fix and if you had an ETA for getting this merged in and package pushed. I only ask so I can evaluate whether it's worth it for me to push a private package with your pending fix just for myself to use temporarily, or whether I should just wait for an official fix. Thanks again for your hard work on this issue!

@JiaLiPassion
Copy link
Collaborator

@dfederm , sure, you can use this temp branch for test now, just update your package.json,

"zone.js": "git://github.com/JiaLiPassion/zone.js#jasmine-dist"

you can test with current status of PR. I will still need to test this PR for little more, please use this branch for now.

JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Feb 13, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Feb 14, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Feb 14, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Feb 14, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Feb 14, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Feb 15, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Feb 15, 2018
JiaLiPassion added a commit to JiaLiPassion/zone.js that referenced this issue Feb 15, 2018
@andreimcristof
Copy link

andreimcristof commented Feb 27, 2018

why is this closed, please?
I have the exact same error and zone.js is updated to the latest version shown in its package.json: 0.8.20. Jasmine core is at: 3.0.0.
is the isssue still requiring further work?
thank you

@JiaLiPassion
Copy link
Collaborator

@andreimcristof , this issue have been fixed, but not released. you can use
"zone.js": "git://github.com/JiaLiPassion/zone.js#jasmine-dist"
in your package.json for now and wait for the next release.

@gezn
Copy link

gezn commented Feb 28, 2018

@JiaLiPassion I moved to the branch as you suggested and it throws the following exception

TypeError: Cannot read property 'length' of undefined
	    at <Jasmine>
	    at UserContext.<anonymous> (webpack:///src/models/sgtinencoding/epc-utils.spec.ts:324:21 <- karma-test-shim.js:67673:52)
	    at ZoneDelegate.invoke (webpack:///node_modules/zone.js/dist/zone.js:388:0 <- karma-test-shim.js:63086:26)
	    at ProxyZoneSpec.onInvoke (webpack:///node_modules/zone.js/dist/proxy.js:79:0 <- karma-test-shim.js:65985:39)
	    at ZoneDelegate.invoke (webpack:///node_modules/zone.js/dist/zone.js:387:0 <- karma-test-shim.js:63085:32)
	    at Zone.run (webpack:///node_modules/zone.js/dist/zone.js:138:0 <- karma-test-shim.js:62836:43)
	    at UserContext.<anonymous> (webpack:///node_modules/zone.js/dist/jasmine-patch.js:96:0 <- karma-test-shim.js:66185:51)
	    at <Jasmine>
	    at ZoneDelegate.invokeTask (webpack:///node_modules/zone.js/dist/zone.js:421:0 <- karma-test-shim.js:63119:31)
	    at Zone.runTask (webpack:///node_modules/zone.js/dist/zone.js:188:0 <- karma-test-shim.js:62886:47)
	    at drainMicroTaskQueue (webpack:///node_modules/zone.js/dist/zone.js:595:0 <- karma-test-shim.js:63293:35)
	    at <Jasmine>

that seems similar to this other issue #399

any ideas?

@emartinez-usgs
Copy link

@JiaLiPassion Thanks. That worked for us and helped out a lot.

christophercr added a commit to christophercr/stark that referenced this issue Mar 23, 2018
dsebastien pushed a commit to NationalBankBelgium/stark that referenced this issue Mar 23, 2018
… in all stark packages and starter (#267)

* feat(stark-testing): create separate stark-testing package. Replace testing specific dependencies by stark-testing in all stark packages and starter. Fixes #68. [#68][#84][#93]

* chore(stark-testing): upgrade dependencies in stark-testing package. Upgrade @types/node in all packages

* fix(stark-testing): downgrade 'jasmine-core' dependency due to an issue with Zone.js (angular/zone.js#1015)

* fix(starter): clean up tsconfig.spec.json for unit testing
dsebastien pushed a commit to NationalBankBelgium/stark that referenced this issue Mar 23, 2018
* feat(stark-testing): create separate stark-testing package. Replace testing specific dependencies by stark-testing in all stark packages and starter. Fixes #68. [#68][#84][#93]

* chore(stark-testing): upgrade dependencies in stark-testing package. Upgrade @types/node in all packages

* fix(stark-testing): downgrade 'jasmine-core' dependency due to an issue with Zone.js (angular/zone.js#1015)

* fix(starter): clean up tsconfig.spec.json for unit testing

* fix(http): fix unit tests. Enhance http demo in Starter [#96]
@alexzaytsev-newsroomly
Copy link

Can this maybe not be closed until this fix is released?

mythz added a commit to NetCoreTemplates/angular-spa that referenced this issue Mar 25, 2018
no idea why ng team releases untested configurations then takes months
to resolve fixes: angular/zone.js#1015
@corvinrok
Copy link

Why is this closed? The issue still exists in the latest revision of stable releases from all components notes (zone.js, rxjs, jasmine).

@JiaLiPassion
Copy link
Collaborator

@corvinrok , @alexzaytsev-newsroomly , please wait for the next release. you can use

"zone.js": "git://github.com/JiaLiPassion/zone.js#jasmine-dist"

for test now.

@martin-mueller-solutions

When is the next release going to be?

@qnlzgl
Copy link

qnlzgl commented Mar 29, 2018

Thanks very much @JiaLiPassion , the fix works perfectly for me.

@richadr
Copy link

richadr commented Apr 3, 2018

For the people watching this issue, the fix appears to have been released so you can remove the hack in your package.json.

https://github.com/angular/zone.js/blob/master/CHANGELOG.md#0821-2018-03-30
(see the jasmine bullet)

@tangjon
Copy link

tangjon commented Apr 10, 2018

Updating zone.js to the latest version worked for me
npm install zone.js@latest --save

SpiralOutDotEu added a commit to SpiralOutDotEu/AngularFire-Auth-app that referenced this issue Apr 15, 2018
SpiralOutDotEu added a commit to SpiralOutDotEu/AngularFire-Auth-app that referenced this issue Apr 15, 2018
@roinou
Copy link

roinou commented Apr 30, 2018

I can confirm: "zone.js": "^0.8.26" and "jasmine-core": "~3.1.0" work together

@ssunny2
Copy link

ssunny2 commented May 1, 2018

A few test cases are still failing after using the above versions. Before upgrading zone.js and jasmine-core, all specs used to pass. Most of the failing ones have 'toBe' and 'toEqual' assertions. It seems the specs are not being tested in order, for example in a describe block with 3 'It' functions, the third(or the second, I found it to be inconsistent) 'It' is being tested first thereby assigning a value to a variable
which is used in the first 'It' function. This breaks the spec for the first 'It' with assertions like toEqual and toBe, where LHS must be equal RHS. Anybody else facing the same issues?

@JiaLiPassion
Copy link
Collaborator

JiaLiPassion commented May 1, 2018

@ssunny2 , this is jasmine 3.0 feature, all test cases will run in random order by default,
https://github.com/jasmine/jasmine/blob/master/release_notes/3.0.md
there is a config to make sure every test cases run in order, but it is not recommended. So I think jasmine want to make sure each it test case should not have dependency.

@JiaLiPassion
Copy link
Collaborator

@roinou, thank you for confirmation.

@ssunny2
Copy link

ssunny2 commented May 1, 2018

@JiaLiPassion Thanks for the clarification. I do understand why it's not recommended,but could you please tell me where I can configure the specs to run in order.

@JiaLiPassion
Copy link
Collaborator

@ssunny2 , sure, you can find it here, https://jasmine.github.io/setup/nodejs.html
Search random, you can set random: false.

@ssunny2
Copy link

ssunny2 commented May 1, 2018

I looked up the file, and found that random is already set to false

{ "spec_dir": "spec", "spec_files": [ "**/*[sS]pec.js" ], "helpers": [ "helpers/**/*.js" ], "stopSpecOnExpectationFailure": false, "random": false }

on running the test by appending --random:false also didn't yield the expected result. Some specs are still failing.

@JiaLiPassion
Copy link
Collaborator

I am not sure which part is wrong, you can try to downgrade to jasmine 2.x, but still use latest zone.js to see what happened, if it worked, maybe your test code have some other conflict with jasmine 3.x. Or you can post your reproduce repo here, I can help to find the reason.

@ssunny2
Copy link

ssunny2 commented May 1, 2018

OK I'll try the steps you suggested, although I'm sure its the TCs that are having conficts with jasmine 3.x. I can't post the repo here though, it isn't my personal project. Thanks for the help.

@denisbeklarov
Copy link

Found a way to disable random mode by jasmine for angular (6 in my case). Put this in karma.conf.js:

module.exports = function (config) {
    config.set({
       // your configuration
        client: {
            jasmine: {
                random: false
            }
        }
}))

@chetankh23
Copy link

chetankh23 commented Oct 3, 2018

I am facing the same issue. I upgraded from Angular 5.2 to Angular 6 and my all the unit tests are breaking apart randomly. I even tried setting up the random mode by jasmine as per @denisbeklarov comment. But its still failing. I tried to use the
"zone.js": "git://github.com/JiaLiPassion/zone.js#jasmine-dist"
in my package.json. But it's still failing. Any idea as to what is causing this ? What is the solution.

@JiaLiPassion
Copy link
Collaborator

@chetankh23, what is the error information?

FranciscoJose74 added a commit to FranciscoJose74/angular-spa that referenced this issue Jan 12, 2024
no idea why ng team releases untested configurations then takes months
to resolve fixes: angular/zone.js#1015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests