DI与Angular 2中的beforeEach

时间:2016-06-08 23:30:44

标签: angular angular2-testing

我想做以下事情:

describe('Questions', () => {
    var rest: RestService;
    var mockBackend: MockBackend;

    beforeEach((done) => {
        console.log('Executing before each');
        inject([RestService, XHRBackend], (_rest: RestService, _mockBackend: MockBackend) => {
            rest = _rest;
            mockBackend = _mockBackend;
            console.log('This never gets executed');
            done();
        });
    });

 ....

永远不会调用回调注入。我错过了什么,或者这是一个更复杂的解决方案吗?

1 个答案:

答案 0 :(得分:0)

我想它应该只是

describe('Questions', () => {
    var rest: RestService;
    var mockBackend: MockBackend;

    beforeEach(inject([RestService, XHRBackend], (_rest: RestService, _mockBackend: MockBackend) => {
            rest = _rest;
            mockBackend = _mockBackend;
            console.log('This never gets executed');
    });
});

取决于您的Angular2版本。