1
這讓我困擾了一會兒。我在同一個文件中有兩個函數。茉莉花 - 間諜功能,在同一個文件中調用
//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'.
我寫的測試中打字稿,然後我有一個大口腳本成功transpiles並運行茉莉規格。一切正常,唯一無法解釋的是爲什麼間諜不工作。一個解釋將不勝感激。
我無法重現此。如果添加'expect(Fun.fun2())。toEqual(「另一個消息」)''測試通過了嗎? – nickflynn
我更新了問題以反映您的評論。 – carchase