jasmine: error ".spies undefined" after all specs run as of v.2.5.x
Somewhere around jasmine.js v.2.5.x the spy clearing logic changed and I started getting
the error: TypeError: Cannot read property 'spies' of undefined in the console.
The visible symptom is that the browser testrunner output is empty.
All tests have run. This error happens during the final cleanup.
Everything worked fine as recently as v.2.4.1 before some kind of change to the cleanup involving spies.
See the errant behavior in this trivial plunker: http://plnkr.co/edit/qixgrpWpf6mgbIfn29zc?p=preview from the Angular 2 docs (I’m the author of the Angular 2 testing chapter).
During the final cleanup, when the id is “suite0”, the error is thrown in …
var spyRegistry = new j$.SpyRegistry({currentSpies: function() {
if(!currentRunnable()) {
throw new Error('Spies must be created in a before function or a spec');
}
return runnableResources[currentRunnable().id].spies; // <-- THROWS HERE
}});
… because the value of runnableResources is the empty object {}.
The following hack gets around the bug:
var spyRegistry = new j$.SpyRegistry({currentSpies: function() {
if(!currentRunnable()) {
throw new Error('Spies must be created in a before function or a spec');
}
if (runnableResources[currentRunnable().id]) {
return runnableResources[currentRunnable().id].spies;
}
return [];
}});
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 5
- Comments: 19 (9 by maintainers)
Commits related to this issue
- docs(testing): revert to jasmine v.2.4.1 Bug in Jasmine v.2.5.x. Stick with v.2.4.1 (as karma-jasmine does) until the following issue is resolved: https://github.com/jasmine/jasmine/issues/1231 Unfo... — committed to IdeaBlade/angular.io by wardbell 8 years ago
- chore(testing): revert to jasmine v.2.4.1 Bug in Jasmine v.2.5.x, reported in https://github.com/jasmine/jasmine/issues/1231 Stick with v.2.4.1 (as karma-jasmine does) until the issue is resolved Unf... — committed to angular/quickstart by wardbell 8 years ago
- chore(testing): revert to jasmine v.2.4.1 Bug in Jasmine v.2.5.x, reported in https://github.com/jasmine/jasmine/issues/1231 Stick with v.2.4.1 (as karma-jasmine does) until the issue is resolved Unf... — committed to angular/quickstart by wardbell 8 years ago
- chore(testing): revert to jasmine v.2.4.1 (#272) Bug in Jasmine v.2.5.x, reported in https://github.com/jasmine/jasmine/issues/1231 Stick with v.2.4.1 (as karma-jasmine does) until the issue is re... — committed to angular/quickstart by wardbell 8 years ago
- docs(testing): revert to jasmine v.2.4.1 (#2697) Bug in Jasmine v.2.5.x. Stick with v.2.4.1 (as karma-jasmine does) until the following issue is resolved: https://github.com/jasmine/jasmine/issues/... — committed to angular/angular.io by wardbell 8 years ago
- docs(testing): revert to jasmine v.2.4.1 (#2697) Bug in Jasmine v.2.5.x. Stick with v.2.4.1 (as karma-jasmine does) until the following issue is resolved: https://github.com/jasmine/jasmine/issues/... — committed to chalin/angular.io by wardbell 8 years ago
- chore(testing): revert to jasmine v.2.4.1 (#272) Bug in Jasmine v.2.5.x, reported in https://github.com/jasmine/jasmine/issues/1231 Stick with v.2.4.1 (as karma-jasmine does) until the issue is re... — committed to talent-programmer/angular-quickstart by talent-programmer 8 years ago
@bisubus looks like
deletedoesn’t do the job in this case. I triedwindow.onload = function() {};and it looks like it works correctly.Hope this helps. Thanks for using Jasmine!
I am indeed using zone.js; thanks for the tip @GZidar !
+1: Our project started throwing this error when we upgrade from 2.4.1 to 2.5.2. If we run jasmine and remove all the test cases, it still throws the same error.
There is quite a bit of code in the example you’ve provided, including some patching of core Jasmine functionality. Given that we’re not seeing this in Jasmine’s own tests or hearing about it from other sources, I’m inclined to say that the issue is arising because of the custom patches to Jasmine that you are using. If you can provide a simpler example without the patching that still causes the error, that would be helpful in diagnosing this issue. At this point, my best guess is that something in the patches is causing the completion callback for the
TreeProcessor(https://github.com/jasmine/jasmine/blob/master/src/core/Env.js#L254) to be called more than once, and the second time everything has already been cleaned for the top suite.If you need to wait to
executeyour Jasmine environment, like in thebrowser-test-shim.jswhenwindow.onload()is called, you should make sure that thatonloadis not getting called when the window loads.