Skip to content

Setting dom adaptor in testing #6034

Closed
Closed

Description

@ovangle

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.

Activity

  1. 0x-r4bbit commented on Dec 20, 2015

    @0x-r4bbit
    Contributor

    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 :)

  2. ovangle commented on Dec 20, 2015

    @ovangle
    Author

    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.

  3. ovangle commented on Dec 21, 2015

    @ovangle
    Author

    When looking at your code which runs the internal angular tests, there is the line

    System.import('angular2/src/platform/browser/browser_adapter').then(function(browser_adapter) {
      browser_adapter.BrowserDomAdapter.makeCurrent();
    })
    

    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...

    Thanks for your help!

  4. matthewdenobrega commented on Dec 30, 2015

    @matthewdenobrega

    +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.

  5. jonnysamps commented on Jan 13, 2016

    @jonnysamps

    Ya, this needs to be documented. Probably will be when the testing docs for dependency injection are published ;)

  6. ericmartinezr commented on Jan 13, 2016

    @ericmartinezr
    Contributor

    @jonnysamps this will change #5975, just in case

  7. angular-automatic-lock-bot commented on Sep 9, 2019

    @angular-automatic-lock-bot

    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.

  8. locked and limited conversation to collaborators on Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions