使用业力和茉莉花进行角度2测试

时间:2017-01-31 05:00:41

标签: unit-testing angular karma-jasmine

我只编写了一个测试用例,当我运行" npm test"从Windows命令行我收到以下错误。不知道是什么问题

> ng test --single-run

PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR
  {
    "stack": "(SystemJS) XHR error (404 Not Found) loading typescript\n\tError loading typescript as \"typescript\" from node_modules/@angular/tsc-wrapped/test/collector.spec.js",
    "originalErr": {},
    "line": 792,
    "sourceURL": "node_modules/systemjs/dist/system.src.js"
  }

PhantomJS 2.1.1(Windows 8 0.0.0):执行0 of 0 ERROR(0.476秒/ 0秒)

npm ERR!测试失败。有关详细信息,请参见上文。

spec.ts

import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By }              from '@angular/platform-browser';
import { Router} from '@angular/router';
import { DebugElement, CUSTOM_ELEMENTS_SCHEMA }    from '@angular/core';

import { myComponent } from './myComponent.component';

describe('myComponent ', () => {

  let comp:    myComponent ;
  let fixture: ComponentFixture<myComponent >;
  let de:      DebugElement;
  let el:      HTMLElement;

  beforeEach(() => {
    TestBed.configureTestingModule({
        schemas: [ CUSTOM_ELEMENTS_SCHEMA ], //to avoid routing
        declarations: [ myComponent ], // declare the test component
    });

    fixture = TestBed.createComponent(myComponent );

    comp = fixture.componentInstance; // myComponent test instance

    // query for the title <h1> by CSS element selector
    de = fixture.debugElement.query(By.css('.left-side-card'));
    el = de.nativeElement;
  });
   it('should display title', () => {
        fixture.detectChanges();
        expect(el.textContent).toContain('My Title');
    });
});

我该怎么办?

我是角色2的新手。环境已在我的项目中设置。我正在练习为组件编写测试用例。

0 个答案:

没有答案