You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to instantiate a test injector, I'm getting the error
TypeError: Cannot read property 'getXHR' of null
at _runtimeCompilerBindings (http://127.0.0.1:8080/node_modules/angular2/src/testing/test_injector.js:94:64)
at Object.createTestInjectorWithRuntimeCompiler (http://127.0.0.1:8080/node_modules/angular2/src/testing/test_injector.js:104:63)
at Object.<anonymous> (http://127.0.0.1:8080/node_modules/angular2/src/testing/testing.js:161:44)
at attemptAsync (http://127.0.0.1:8080/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1916:24)
at QueueRunner.run (http://127.0.0.1:8080/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1871:9)
at QueueRunner.execute (http://127.0.0.1:8080/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1859:10)
at Spec.Env.queueRunnerFactory (http://127.0.0.1:8080/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:697:35)
at Spec.execute (http://127.0.0.1:8080/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:359:10)
at Object.fn (http://127.0.0.1:8080/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:2479:37)
at attemptAsync (http://127.0.0.1:8080/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1916:24)
which is referencing DOM.getXHR(), however the dom adaptor is never set in my test environment, since the test suite is not bootstrapped.
Can you please provide more context? What do you mean with "instantiating a test injector"? Instantiating an Injector manually for your tests? Or generally using an injector in tests?
Sorry, I didn't include much information because I assumed the problem would be a common and obvious one and that I was an idiot for not being able to call inject in my tests. By 'instantiating a test injector', I meant 'when angular is trying to construct one for me', I'm not trying to do it manually.
Here's a plunk demonstrating the error, as you can see it's pretty minimal.
which would fix the problem, so maybe that just needs to be documented somewhere. I didn't find it initially because that code is outside the modules folder.
However, (and a call to initialise reflector.reflectionCapabilities) would be better suited to a bootstrapTests function in the angular2/testing library as part of the public testing API, since otherwise it would expose angular internals (or, perhaps more usefully, as part of the angular2/platform/browser API, to preserve the platform independence of the testing library). But I'm probably out of line for suggesting a fix (and I've found my workaround in the meantime), so...
+1 for a fix for this - it's possible to work around but it's not obvious when you start writing tests that you need to set up the browser adapter for the injector to work.
Activity
0x-r4bbit commentedon Dec 20, 2015
Can you please provide more context? What do you mean with "instantiating a test injector"? Instantiating an Injector manually for your tests? Or generally using an injector in tests?
More code would be helpful, ideally a plunk :)
ovangle commentedon Dec 20, 2015
Sorry, I didn't include much information because I assumed the problem would be a common and obvious one and that I was an idiot for not being able to call
injectin my tests. By 'instantiating a test injector', I meant 'when angular is trying to construct one for me', I'm not trying to do it manually.Here's a plunk demonstrating the error, as you can see it's pretty minimal.
ovangle commentedon Dec 21, 2015
When looking at your code which runs the internal angular tests, there is the line
which would fix the problem, so maybe that just needs to be documented somewhere. I didn't find it initially because that code is outside the
modulesfolder.However, (and a call to initialise
reflector.reflectionCapabilities) would be better suited to abootstrapTestsfunction in theangular2/testinglibrary as part of the public testing API, since otherwise it would expose angular internals (or, perhaps more usefully, as part of theangular2/platform/browserAPI, to preserve the platform independence of the testing library). But I'm probably out of line for suggesting a fix (and I've found my workaround in the meantime), so...Thanks for your help!
matthewdenobrega commentedon Dec 30, 2015
+1 for a fix for this - it's possible to work around but it's not obvious when you start writing tests that you need to set up the browser adapter for the injector to work.
jonnysamps commentedon Jan 13, 2016
Ya, this needs to be documented. Probably will be when the testing docs for dependency injection are published ;)
ericmartinezr commentedon Jan 13, 2016
@jonnysamps this will change #5975, just in case
angular-automatic-lock-bot commentedon Sep 9, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.