Unit testing 使用karma和jasmine进行角度2测试

Unit testing 使用karma和jasmine进行角度2测试,unit-testing,angular,karma-jasmine,Unit Testing,Angular,Karma Jasmine,我只写了一个测试用例,当我在windows中从命令行运行“npm测试”时,我得到了以下错误。不知道是什么问题 > 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 nod

我只写了一个测试用例,当我在windows中从命令行运行“npm测试”时,我得到了以下错误。不知道是什么问题

> 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/0错误(0.476秒/0秒)

npm错误!测试失败。请参见上文了解更多详细信息

规格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');
    });
});
从'@angular/core/testing'导入{ComponentFixture,TestBed};
从“@angular/platform browser”导入{By}”;
从'@angular/Router'导入{Router};
从'@angular/core'导入{DebugElement,CUSTOM_ELEMENTS_SCHEMA};
从“./myComponent.component”导入{myComponent};
描述('myComponent',()=>{
let comp:myComponent;
let夹具:组件夹具;
设de:DebugElement;
让el:HTMLElement;
在每个之前(()=>{
TestBed.configureTestingModule({
模式:[自定义元素\u模式],//避免路由
声明:[myComponent],//声明测试组件
});
fixture=TestBed.createComponent(myComponent);
comp=fixture.componentInstance;//myComponent测试实例
//按CSS元素选择器查询标题
de=fixture.debugElement.query(By.css('.left-side-card');
el=自然元素;
});
它('应该显示标题',()=>{
fixture.detectChanges();
expect(el.textContent).toContain(“我的标题”);
});
});
我该怎么办


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

用测试用例代码以及安装步骤更新帖子karma@Aravind使用测试用例代码更新它是表单元素吗。左侧卡片对应一个表单元素?@Aravind-不,它只是一个带有“.left side card”类名的div