Skip to content

Commit

Permalink
Should not throw on sealed objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSavior committed Nov 7, 2015
1 parent c15674c commit e2a27c3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/getDefinePropertySrc.js
Expand Up @@ -11,9 +11,8 @@ var srcs = {
};

function getDefinePropertySrc() {
var src = "if ((typeof(module.exports) === 'function' || \n" +
"typeof(module.exports) === 'object') &&\n"+
"Object.isExtensible(module.exports)) {\n";
var src = "if (typeof(module.exports) === 'function' || \n" +
"typeof(module.exports) === 'object') {\n";

src += Object.keys(srcs).reduce(function forEachSrc(preValue, value) {
return preValue += "Object.defineProperty(module.exports, '" +
Expand Down
1 change: 1 addition & 0 deletions test/testModules/sealedObject.js
@@ -0,0 +1 @@
module.exports = {};
6 changes: 6 additions & 0 deletions test/testModules/sharedTestCases.js
Expand Up @@ -226,6 +226,12 @@ describe("rewire " + (typeof testEnv === "undefined"? "(node)": "(" + testEnv +
}).to.not.throwException();
});

it("should not be a problem to have a module that exports a sealed object", function() {
expect(function() {
var rewired = rewire("./sealedObject.js");
}).to.not.throwException();
});

it("should not influence the original require if nothing has been required within the rewired module", function () {
rewire("./emptyModule.js"); // nothing happens here because emptyModule doesn't require anything
expect(require("./moduleA.js").__set__).to.be(undefined); // if restoring the original node require didn't worked, the module would have a setter
Expand Down

0 comments on commit e2a27c3

Please sign in to comment.