【发布时间】:2020-06-30 22:32:10
【问题描述】:
我有以下文件
// definition file
export namespace Foo {
export function foo() {
bar();
}
export function bar() {
throw 'not implemented yet'
}
}
// test file
import { Foo } from 'fooFile'
describe('', () => {
it('', () => {
const sandbox = sinon.createSandbox();
sandbox.stub(Foo, 'bar');
Foo.foo(); // expected not to throw since I stubbed bar
});
});
我不知道为什么它仍然抛出。到目前为止,我已经能够存根从没有命名空间 (import * as Foo from) 的文件中导入的函数、类中的方法和静态方法,但我找不到这个存根的语法。
【问题讨论】:
-
当您执行
sandbox.stub(Foo.bar)时会发生什么? -
@KarolMajewski 存根不起作用,restore() 不会删除存根。
标签: typescript namespaces sinon stub