【发布时间】:2016-09-02 23:44:08
【问题描述】:
- 诗乃版本:v2.0.0-pre.2
- 环境:Windows 10
- 您正在使用的其他库:Typescript、babel、mocha、chai
您预计会发生什么?
我希望能够在类中存根箭头函数。
实际发生的情况
我不能存根箭头函数,但是,我可以存根类原型函数。
FAILED TESTS:
ExampleClass tests
× should stub thisDoesntWork arrow function
Chrome 52.0.2743 (Windows 10 0.0.0)
TypeError: Attempted to wrap undefined property thisDoesntWork as function
at wrapMethod (webpack:///~/sinon/pkg/sinon.js:3138:0 <- test-bundler.js:7377:21)
at Object.stub (webpack:///~/sinon/pkg/sinon.js:2472:0 <- test-bundler.js:6711:12)
at Context.<anonymous> (webpack:///src/stores/sinon.test.ts:22:51 <- test-bundler.js:96197:72)
如何重现
export class ExampleClass {
thisWorks() {
return 0;
}
thisDoesntWork = () => {
return 0;
}
}
describe("ExampleClass tests", () => {
it("should stub thisWorks function", () => {
let stubFunctionA = sinon.stub(ExampleClass.prototype, "thisWorks");
});
it("should stub thisDoesntWork arrow function", () => {
let stubFunctionB = sinon.stub(ExampleClass, "thisDoesntWork");
});
});
【问题讨论】:
标签: javascript typescript sinon