简体   繁体   中英

Property 'mock' does not exist on type 'IAngularStatic'

I want to use the mock to make a new class,but i don't konw why this mock does not exist on type 'IAngularStatic'.following is my code.

 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 mock ( @types/angular-mocks ) 的@types/angular-mocks ,它位于另一个项目中而不是 angularjs ( @types/angular )。

npm install --save-dev @types/angular-mocks

Actually the following would probably be preferred: import 'angular-mocks'; which can be added at the top of your file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM