【发布时间】:2016-11-21 07:52:48
【问题描述】:
这困扰了我一段时间。我在同一个文件中有两个函数。
//fun.ts
export function fun1(){
let msg = fun2();
return msg;
}
export function fun2(): string{
return "Some message";
}
我有一个打字稿规范,它存根 fun2 并调用 fun1。
//fun.spec.ts
import * as Fun from 'fun';
describe('Stubing', () => {
it('should stub the return value', () => {
spyOn(Fun, 'fun2').and.returnValue("A different message");
expect(Fun.fun1()).toEqual("A different message")
});
});
但是当我运行规范时,我得到的输出是
Failures:
1) Stubing should stub the return value
1.1) Expected 'Some message' to equal 'A different message'.
我在 typescript 中编写了测试,然后我有一个 gulp 脚本,它成功地转换并运行了 jasmine 规范。一切正常,我唯一想不通的是为什么间谍不起作用。将不胜感激。
【问题讨论】:
-
我无法重现这个。如果您添加
expect(Fun.fun2()).toEqual("A different message"),您的测试是否通过? -
我更新了问题以反映您的评论。
标签: node.js unit-testing testing typescript jasmine