angularjs – ‘IAngularStatic’类型中不存在属性’mock’

我想使用mock来创建一个新类,但我不知道为什么这个mock在类型’IAngularStatic’上不存在.下面是我的代码.

import {} from 'jasmine';
import * as angular from 'angular';
import {StrategyTables} from "./strategyTables.component";
import {StrategyTablesService} from "./strategyTables.service";
import {Router} from "@angular/router";
import {Location } from '@angular/common';
import {inject,async,TestBed} from '@angular/core/testing';
describe('strategyTables.component',() => {

  class MockstrategyService extends StrategyTablesService{
    getContactById(id:number){
      return{
        "name": "lee"
      };
    }

  }
  beforeEach(() => {
    angular.mock.module(($provide) => {
      TestBed.configureTestingModule({
        providers: [
          $provide.value(StrategyTablesService, { useClass:MockstrategyService })
      ]
    });
    });
  });

最佳答案 实际上以下可能是首选:

进口’angular-mocks’;可以添加到文件顶部.

点赞