0

私は非常に簡単なテストをしています。できます。

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

対応する依存関係を読み込もうとしています。しかし、それは機能しません:

import {beforeEachProviders} from 'angular2/testing';

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

なんで?

ブラウザのコンソールからのエラー メッセージ:

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
    $@http://0.0.0.0:8000/build/vendors/systemjs/dist/system-polyfills.js:4:8738
    H@http://0.0.0.0:8000/build/vendors/systemjs/dist/system-polyfills.js:4:8372
    [7]</</</</R.prototype.when@http://0.0.0.0:8000/build/vendors/systemjs/dist/system-polyfills.js:4:12046
    [7]</</</</b.prototype.run@http://0.0.0.0:8000/build/vendors/systemjs/dist/system-polyfills.js:4:11080
    [3]</</</t.prototype._drain@http://0.0.0.0:8000/build/vendors/systemjs/dist/system-polyfills.js:4:2985
    t/this.drain@http://0.0.0.0:8000/build/vendors/systemjs/dist/system-polyfills.js:4:2652
    e@http://0.0.0.0:8000/build/vendors/systemjs/dist/system-polyfills.js:4:4575
    Zone</ZoneDelegate</ZoneDelegate.prototype.invoke@http://0.0.0.0:8000/build/vendors/angular2/bundles/angular2-polyfills.js:332:20
    Zone</Zone</Zone.prototype.runGuarded@http://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
4

1 に答える 1

1

私の場合はうまくいきます。ここを見て、

動作デモ

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);
  });
});
于 2016-04-01T03:04:15.023 に答える