Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 在Ionic Provider中建立试验台_Unit Testing_Ionic Framework_Karma Jasmine - Fatal编程技术网

Unit testing 在Ionic Provider中建立试验台

Unit testing 在Ionic Provider中建立试验台,unit-testing,ionic-framework,karma-jasmine,Unit Testing,Ionic Framework,Karma Jasmine,我对离子测试和单元测试是个新手。目前的版本是3.12.0。我使用Karma和Jasmine进行单元测试 我有一个名为测试服务的提供商。ts import { Injectable } from '@angular/core'; import { Http } from '@angular/http'; import 'rxjs/add/operator/map'; /* Generated class for the TestServiceProvider provider. See

我对离子测试和单元测试是个新手。目前的版本是3.12.0。我使用Karma和Jasmine进行单元测试

我有一个名为测试服务的提供商。ts

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';

/*
  Generated class for the TestServiceProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class TestServiceProvider {

  constructor(public http: Http) {
    console.log('Hello TestServiceProvider Provider');
  }

}
然后,我在同一文件夹中有一个测试规范,如下所示,其中包含一个带有测试台的简单测试

import { TestServiceProvider } from './test-service';
import { TestBed, TestModuleMetadata, async, ComponentFixture } from '@angular/core/testing';

describe('Test Service', () => {
  let component: TestServiceProvider;
  let fixture: ComponentFixture<TestServiceProvider>;

  beforeEach(async( () => {
    TestBed.configureTestingModule({
      imports: [TestServiceProvider]
    }).compileComponents;
  }));

  beforeEach( () => {
    fixture = TestBed.createComponent(TestServiceProvider);
    component = fixture.componentInstance;
  });

  it('should add numbers', () => {
    expect(1+1).toBe(2);
  });
});

我做错了什么?我该如何解决

TestServiceProvider必须在声明中,而不是在导入中

按以下方式更改代码:

beforeEach(async( () => {
    TestBed.configureTestingModule({
      declarations: [TestServiceProvider]
    }).compileComponents;
  }));

TestServiceProvider必须在声明中,而不是在导入中

按以下方式更改代码:

beforeEach(async( () => {
    TestBed.configureTestingModule({
      declarations: [TestServiceProvider]
    }).compileComponents;
  }));

我使用了上面的代码,现在给出了一个错误
模块'DynamicTestModule'声明的意外值'TestServiceProvider'。请添加@Pipe/@Directive/@组件注释。
我使用了上述代码,现在给出了一个错误
模块'DynamicTestModule'声明的意外值'TestServiceProvider'。请添加@Pipe/@Directive/@组件注释。