현재 단위 테스트에서 종속성 모의 (mock)를 주입 할 수 있도록 https://github.com/felixge/node-sandboxed-module을 실험하고 있습니다.node-sandboxed-module 및 should.js가 함께 작동하지 않습니까?
myModule.js :
module.exports = {
func1: function() {
return {
'THIS': {
'IS': {
'SPARTA': {
'DONT': 'TRUST ME'
}
}
}
};
}
};
인 MyModule-test.js : 약
var should = require('should');
var sandboxedModule = require('sandboxed-module');
var myModule1 = require('./myModule');
var myModule2 = sandboxedModule.require('./myModule');
describe('myModule', function() {
it('should return the object', function() {
myModule1.func1().should.be.instanceOf(Object);
});
describe('returned object', function() {
it('should have the correct properties', function() {
myModule1.func1().THIS.should.have.property('IS');
});
});
});
describe('Sandboxed myModule', function() {
describe('returned object', function() {
it('should have the should property', function() {
should.exist(myModule2.func1().should);
});
describe('nested objects', function() {
it('should have the should property', function() {
should.exist(myModule2.func1().THIS.should);
should.exist(myModule2.func1().THIS.IS.should);
});
});
});
});
이 테스트 밝혀이 모듈은 샌드 박스 모듈에서 생성 된 개체에 대한 should.js 사망 샌드 박스 처리 된 모듈에 오류가 발생했습니다.
1) Sandboxed myModule returned object should have the should property:
AssertionError: expected undefined to exist
2) Sandboxed myModule returned object nested objects should have the should property:
AssertionError: expected undefined to exist
나는 객체 생성자를 사용하여 shoul 프로토 타입 D의 숨겨진 재산을 사용할 수 있지만, 그 작업 중 하나를하지 않았다 :
var myModule2 = sandboxedModule.require('./myModule', {
globals: {
Object: Object
}
});
재미있는 것은 내가 https://github.com/nathanmacinnes/injectr처럼 비슷한 샌드 박스 - 모듈을 사용하는 경우 같은 문제가 발생합니다. 이것은 내가 누가 노드 - 샌드 박스 - 모듈과 인젝터, 노드 자체, should.js, 아니면 나조차도 무엇인가 잘못하고있는 사람에 대해 혼란 스럽다. :)
도움 주셔서 감사합니다.