Jasmine 观众/茉莉花更换服务呼叫

Jasmine 观众/茉莉花更换服务呼叫,jasmine,angular-spectator,spectator,Jasmine,Angular Spectator,Spectator,我在用茉莉花做测试。我试图让我的注入服务伪造呼叫并返回值,但真正的服务正在被呼叫 我是这样创建工厂的: const createComponent=createComponentFactory({ 组件:CreateRequestComponent, 检测更改:错误, 模拟:[ 请求服务 ] }) 然后在测试中,我尝试通过模拟服务替换调用 const requestService=constander.inject(requestService) requestService.postRequ

我在用茉莉花做测试。我试图让我的注入服务伪造呼叫并返回值,但真正的服务正在被呼叫

我是这样创建工厂的:

const createComponent=createComponentFactory({
组件:CreateRequestComponent,
检测更改:错误,
模拟:[
请求服务
]
})
然后在测试中,我尝试通过模拟服务替换调用

const requestService=constander.inject(requestService)
requestService.postRequest.and.callFake(()=>of({id}))
当我的组件调用
postRequest
时,它没有使用假版本,而是调用实际的
RequestService
方法

很明显,我并没有把事情正确地联系起来,但是对于茉莉花和测试来说,我真的是一个新手,我不知道会发生什么。
RequestService
是通过组件的构造函数注入的,在组件上没有明确列为提供者