2016-03-31 19 views
0

Çok basit bir test var. İşe yarıyor.Angular2 testi. Bağımlılık nasıl yüklenir?

Karşılık gelen bağımlılıkları yüklemeye çalışıyorum. Ama işe yaramıyor:

import {beforeEachProviders} from 'angular2/testing'; 

describe('Parser',() => { 
    beforeEachProviders(() => []); // Don't works with this line 
    it('getData works properly',() => { 
    expect(1).toEqual(1); 
    }); 
}); 

Neden? Tarayıcının konsoldan

Hata mesajı: benim durumumda

Error: @http://0.0.0.0:8000/build/vendors/angular2/src/facade/async.js:10:17 
    @http://0.0.0.0:8000/build/vendors/angular2/src/facade/async.js:1:1 
    @http://0.0.0.0:8000/build/vendors/angular2/src/core/change_detection/abstract_change_detector.js:9:15 
    @http://0.0.0.0:8000/build/vendors/angular2/src/core/change_detection/abstract_change_detector.js:1:1 
    @http://0.0.0.0:8000/build/vendors/angular2/src/core/change_detection/dynamic_change_detector.js:9:34 
    @http://0.0.0.0:8000/build/vendors/angular2/src/core/change_detection/dynamic_change_detector.js:1:1 
    @http://0.0.0.0:8000/build/vendors/angular2/src/core/change_detection/proto_change_detector.js:6:33 
    @http://0.0.0.0:8000/build/vendors/angular2/src/core/change_detection/proto_change_detector.js:1:1 
    @http://0.0.0.0:8000/build/vendors/angular2/src/core/change_detection/change_detection.js:36:31 
    @http://0.0.0.0:8000/build/vendors/angular2/src/core/change_detection/change_detection.js:1:1 
    @http://0.0.0.0:8000/build/vendors/angular2/src/core/change_detection.js:6:26 
    @http://0.0.0.0:8000/build/vendors/angular2/src/core/change_detection.js:1:1 
    @http://0.0.0.0:8000/build/vendors/angular2/src/core/metadata/directives.js:17:26 
    @http://0.0.0.0:8000/build/vendors/angular2/src/core/metadata/directives.js:1:1 
    @http://0.0.0.0:8000/build/vendors/angular2/src/core/metadata.js:13:20 
    @http://0.0.0.0:8000/build/vendors/angular2/src/core/metadata.js:1:1 
    @http://0.0.0.0:8000/build/vendors/angular2/core.js:9:10 
    @http://0.0.0.0:8000/build/vendors/angular2/core.js:1:1 
    @http://0.0.0.0:8000/build/vendors/angular2/src/testing/test_injector.js:1:103 
    @http://0.0.0.0:8000/build/vendors/angular2/src/testing/test_injector.js:1:1 
    @http://0.0.0.0:8000/build/vendors/angular2/src/testing/testing.js:6:23 
    @http://0.0.0.0:8000/build/vendors/angular2/src/testing/testing.js:1:1 
    @http://0.0.0.0:8000/build/vendors/angular2/testing.js:12:10 
    @http://0.0.0.0:8000/build/vendors/angular2/testing.js:1:1 
    @http://0.0.0.0:8000/build/app/module/parser/parser.spec.js:3:17 
    @http://0.0.0.0:8000/build/app/module/parser/parser.spec.js:1:1 
    [email protected]://0.0.0.0:8000/build/vendors/systemjs/dist/system-polyfills.js:4:8738 
    [email protected]://0.0.0.0:8000/build/vendors/systemjs/dist/system-polyfills.js:4:8372 
    [7]</</</</[email protected]://0.0.0.0:8000/build/vendors/systemjs/dist/system-polyfills.js:4:12046 
    [7]</</</</[email protected]://0.0.0.0:8000/build/vendors/systemjs/dist/system-polyfills.js:4:11080 
    [3]</</</[email protected]://0.0.0.0:8000/build/vendors/systemjs/dist/system-polyfills.js:4:2985 
    t/[email protected]://0.0.0.0:8000/build/vendors/systemjs/dist/system-polyfills.js:4:2652 
    [email protected]://0.0.0.0:8000/build/vendors/systemjs/dist/system-polyfills.js:4:4575 
    Zone</ZoneDelegate</[email protected]://0.0.0.0:8000/build/vendors/angular2/bundles/angular2-polyfills.js:332:20 
    Zone</Zone</[email protected]://0.0.0.0:8000/build/vendors/angular2/bundles/angular2-polyfills.js:241:29 
    Zone</Zone</Zone.prototype.wrap/<@http://0.0.0.0:8000/build/vendors/angular2/bundles/angular2-polyfills.js:217:25 

    Evaluating http://0.0.0.0:8000/rxjs/Subject.js 
    Evaluating http://0.0.0.0:8000/build/vendors/angular2/src/facade/async.js 
    Evaluating http://0.0.0.0:8000/build/vendors/angular2/src/core/change_detection/abstract_change_detector.js 
    Evaluating http://0.0.0.0:8000/build/vendors/angular2/src/core/change_detection/dynamic_change_detector.js 
    Evaluating http://0.0.0.0:8000/build/vendors/angular2/src/core/change_detection/proto_change_detector.js 
    Evaluating http://0.0.0.0:8000/build/vendors/angular2/src/core/change_detection/change_detection.js 
    Evaluating http://0.0.0.0:8000/build/vendors/angular2/src/core/change_detection.js 
    Evaluating http://0.0.0.0:8000/build/vendors/angular2/src/core/metadata/directives.js 
    Evaluating http://0.0.0.0:8000/build/vendors/angular2/src/core/metadata.js 
    Evaluating http://0.0.0.0:8000/build/vendors/angular2/core.js 
    Evaluating http://0.0.0.0:8000/build/vendors/angular2/src/testing/test_injector.js 
    Evaluating http://0.0.0.0:8000/build/vendors/angular2/src/testing/testing.js 
    Evaluating http://0.0.0.0:8000/build/vendors/angular2/testing.js 
    Evaluating http://0.0.0.0:8000/build/app/module/parser/parser.spec.js 
    Error loading http://0.0.0.0:8000/build/app/module/parser/parser.spec.js system-polyfills.js:4:8738 
+0

Eğer bağımlılıkları yükleme için yapılandırma eklemek Could, burada bak? Karma kullanıyor musunuz, değil mi? Bunun yanı sıra, 'anlaĢtırma'/'testini' angular2/test '' den aldığınızdan emin olun. Angular2, çoğu/tüm yasemin işlevlerini yayar. –

cevap

1

İşleri cezası.

working demo

import { 
    beforeEach, 
    describe, 
    expect, 
    it, 
    injectAsync, 
    TestComponentBuilder, 
    beforeEachProviders, 

} from 'angular2/testing'; 

describe('Parser',() => { 
    it('getData works properly',() => { 
    expect(1).toEqual(1); 
    }); 
}); 

describe('Parser',() => { 
    beforeEachProviders(() => []); // works fine in my case. 
    it('getData works properly',() => { 
    expect(1).toEqual(1); 
    }); 
});