【发布时间】:2021-04-06 13:19:25
【问题描述】:
问题:当我为服务文件运行单元测试用例时,它会说
'Spec 'MerchantsService getMerchantData' 没有任何期望。' 请帮忙,而不是显示 console.log。提前致谢。
下面是我的服务文件包含的内容
getMerchantData(searchParams: any): Observable<any> {
return this.http.get(`${this.baseUrl}/merchants-data-url${searchParams}`)
}
以下是服务的规范文件。
import { async, inject, TestBed } from '@angular/core/testing'
import { MerchantsService } from './merchants.service'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { ReactiveFormsModule, FormsModule } from '@angular/forms'
describe('MerchantsService', () => {
let service: MerchantsService
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule, ReactiveFormsModule, FormsModule],
})
service = TestBed.inject(MerchantsService)
})
it('should be created', () => {
expect(service).toBeTruthy()
})
it('getMerchantData', async() => {
service.getMerchantData('?page=1').subscribe((res) => {
console.log('getMerchantData', res.data)
expect(res.data.length).toBeGreaterThan(0)
})
})
})
【问题讨论】:
标签: javascript angular unit-testing karma-jasmine