diff --git a/lib/getDefinePropertySrc.js b/lib/getDefinePropertySrc.js index 039f442..9ec4bde 100644 --- a/lib/getDefinePropertySrc.js +++ b/lib/getDefinePropertySrc.js @@ -12,7 +12,7 @@ var srcs = { function getDefinePropertySrc() { var src = "if (typeof(module.exports) === 'function' || \n" + - "(typeof(module.exports) === 'object' && Object.isExtensible(module.exports))) {\n"; + "(typeof(module.exports) === 'object' && module.exports !== null && Object.isExtensible(module.exports))) {\n"; src += Object.keys(srcs).reduce(function forEachSrc(preValue, value) { return preValue += "Object.defineProperty(module.exports, '" + diff --git a/testLib/null.js b/testLib/null.js new file mode 100644 index 0000000..b894a23 --- /dev/null +++ b/testLib/null.js @@ -0,0 +1 @@ +module.exports = null; diff --git a/testLib/sharedTestCases.js b/testLib/sharedTestCases.js index df9a06a..54e4218 100644 --- a/testLib/sharedTestCases.js +++ b/testLib/sharedTestCases.js @@ -220,12 +220,18 @@ describe("rewire " + (typeof testEnv === "undefined"? "(node)": "(" + testEnv + expect(rewired.__get__("someVar")).to.be("hello"); }); - it("should not be a problem to have a module that exports a primitive", function() { + it("should not be a problem to have a module that exports a boolean", function() { expect(function() { var rewired = rewire("./boolean.js"); }).to.not.throwException(); }); + it("should not be a problem to have a module that exports null", function() { + expect(function() { + var rewired = rewire("./null.js"); + }).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");