8
我想知道如果我使用ESB进口/出口与巴贝尔如何间谍/存根茉莉花功能?Jasmine:如何在ES6上监视导入的函数/构造函数?
import MobileDetect from 'mobile-detect';
it('should spy MobileDetect',() => {
MobileDetect = jasmine.createSpy('MobileDetect');
});`
第一个问题是,我不能改写只读模块
模块构建失败:SyntaxError: /Users/oleg/projects/rp/popup/lib/spec/popup.spec.js: "MobileDetect" is read-only
it('should spy MobileDetect',() => {
console.log(MobileDetect.prototype.constructor === MobileDetect); //true
spyOn(MobileDetect.prototype, 'constructor');
console.log(MobileDetect.prototype.constructor === MobileDetect); //false
});`
我试过这种方法,但它并没有工作过。 .. MobileDetect.prototype.constructor窥探,但MobileDetect直接不是。
您对这个问题有什么看法?
您不能窥探'MobileDetect',因为变量的值不能被重写为新的间谍功能。我的猜测是:如果你做了'var myMobileDetect = MobileDetect',然后窥探'myMobileDetect',会怎么样?显然,你需要改变你的代码来使用myMobileDetect。 – apsillers
我想知道你在测试中想要完成什么。你是否希望创建一个模仿MobileDetect方法的间谍? (即模拟) –