【发布时间】:2020-02-25 13:20:22
【问题描述】:
在我的测试规范中,我想为 2 件东西投保。
1. dummy data maching with model and get response.
2. find the `api` called with correct url.
我正在尝试这些,但出现以下错误:
SubsystemServiceService › get susbsytem collection › should call get the subsytem collection
我还想更新我的规范文件以确保满足我的要求。有人请帮我吗?
这是我的 spec.ts 文件:
import { TestBed } from '@angular/core/testing';
import { HttpClient } from '@angular/common/http';
import { cold } from 'jasmine-marbles';
import { ModelSubSystem } from './../models/model.subSystem';
import { SubsystemService } from './subsystem-service';
describe('SubsystemServiceService', () => {
let service: SubsystemService;
let http: HttpClient;
const data1 = {
Id: 0,
Name: 'subsystem1',
IsDeletePossible: true,
CreatedBy: '',
CreatedDate: new Date(),
UpdatedBy: '',
UpdatedDate: new Date(),
UpdatedByName: '',
CreatedByName: ''
} as ModelSubSystem;
const data2 = {
Id: 0,
Name: 'subsystem2',
IsDeletePossible: true,
CreatedBy: '',
CreatedDate: new Date(),
UpdatedBy: '',
UpdatedDate: new Date(),
UpdatedByName: '',
CreatedByName: ''
} as ModelSubSystem;
const subsystems = [data1, data2];
beforeEach(() => {
TestBed.configureTestingModule({
providers: [{ provide: HttpClient, useValue: { get: jest.fn() } }]
});
service = TestBed.get(SubsystemService);
http = TestBed.get(HttpClient);
});
describe('get susbsytem collection', () => {
it('should call get the subsytem collection', () => {
const response = cold('(-a|)', { a: subsystems });
http.get = jest.fn(() => response);
expect(http.get).toHaveBeenCalledWith(`https://ewsanedevaoscmsapi01-as.websites.net/api/SubSystem`);
});
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
【问题讨论】:
标签: angular jestjs angular8 angular-test