我已经按照Sitepen的指南来模拟AMD模块(LINK),但是当我尝试两次模拟同一个模块时,模拟失败了,告诉我我的模拟没有构造函数。它在AMD-Mocker中崩溃了:
try {
originalModule = require(moduleId); [...]
}
有没有人偶然发现这个问题并找到了解决方案?创建两个测试文件也无济于事。
这是我的压缩代码:
define(function (require) {
var registerSuite = require('intern!object');
var assert = require('intern/chai!assert');
var amdMocker = require('support/AMDMocker');
registerSuite( function(){
var Hello;
return{
before: function(){
return amdMocker.mock('amd/Hello', {
'amd/Resolver': 'support/ResolverMocked'
}).then(function (mocked) {
Hello = mocked;
});
},
name: 'helloMocked',
'greet': function () {
var hello = new Hello();
}
}
});
registerSuite( function(){
var Hello2;
return{
before: function(){
return amdMocker.mock('amd/Hello', {
'amd/Resolver': 'support/ResolverMocked'
}).then(function (mocked) {
Hello2 = mocked;
});
},
name: 'helloMocked2',
'greet': function () {
var hello = new Hello2(); // here it crashes
}
}
});
});