Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import components in unit tests #124

Closed
arozwalak opened this issue Nov 2, 2015 · 4 comments
Closed

import components in unit tests #124

arozwalak opened this issue Nov 2, 2015 · 4 comments

Comments

@arozwalak
Copy link

I'm trying to import app.ts into unit tests, but I don't know how it should work. I used https://github.com/juliemr/ng2-test-seed to get tests working so my test file looks like this:

/// <reference path="../../src/typings/_custom.d.ts" />
import { it, iit, describe, expect, inject, injectAsync, beforeEachProviders, fakeAsync, tick } from 'angular2/testing';

import { App } from '../../src/app/app';

describe('App', () => {
  beforeEachProviders(() => [App])

  it('should provide test', inject([App], (app) => {
    expect(app.test).toEqual('test');
  }));
})

and my app.ts files:

import { Component, Injectable } from 'angular2/angular2';

@Component({
    selector: 'app',
    template: '<div></div>'
})

@Injectable()
export class App {
    test: String = 'test';
    constructor() {
    }
}

In result I'm getting:

Chrome 46.0.2490 (Mac OS X 10.10.5) App should provide test FAILED
        TypeError: Cannot read property 'getXHR' of undefined
            at _getAppBindings (/Users/arozwalak/Sites/gherkin/admin-portal/admin-portal-web/spec.bundle.js:34118:63 <- webpack:///~/angular2/src/testing/test_injector.js:91:33)
            at Object.createTestInjector (/Users/arozwalak/Sites/gherkin/admin-portal/admin-portal-web/spec.bundle.js:34128:80 <- webpack:///~/angular2/src/testing/test_injector.js:101:0)
            at Object.<anonymous> (/Users/arozwalak/Sites/gherkin/admin-portal/admin-portal-web/spec.bundle.js:33929:49 <- webpack:///~/angular2/src/testing/testing.js:67:0)
Chrome 46.0.2490 (Mac OS X 10.10.5): Executed 2 of 3 (1 FAILED) (skipped 1) (0.115 secs / 0.019 secs)

I also tried with injectAsync but have the same result.

@ronanbrett
Copy link

I had the same problem, if you add

var domAdapter = require('angular2/src/core/dom/browser_adapter').BrowserDomAdapter;
domAdapter.makeCurrent();

to the spec.bundle.js after the requires, seems to solve it for me.

@matthewdenobrega
Copy link

@PatrickJS
Copy link
Owner

@ao21 can you make a pull-request

@PatrickJS
Copy link
Owner

done via #128

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants