我有以下角度服务及其茉莉花测试。测试调用 f1() 并监视 f2()。函数 f2 接受变量 v2 并修改它(将字段 a 设置为 3)。函数 f2 应该用 v2 调用(如 f1 中声明的那样),但我的测试在toHaveBeenCalledWith 上失败,并说实际调用是在 f2 函数调用之后使用对象进行的。jasmine 是否在函数调用后匹配 .toHaveBeenCalledWith 的参数,这不应该是推荐的方式,或者我在这里犯了一些错误。
服务:
export class JasmineTestClass{
constructor(){
}
f2(v2){
v2.a = 3
};
f1(v1){
let v2 = {
a:30
};
this.f2(v2);
}
}
Run Code Online (Sandbox Code Playgroud)
测试:
describe('Test', () => {
let service: JasmineTestClass;
beforeEach(() => {
service = new JasmineTestClass();
spyOn(service, 'f2').and.callThrough();
});
let v1 = {
a:2, b:3
};
let v2 = {
a:30
};
it('should succeed', () …Run Code Online (Sandbox Code Playgroud)