Skip to content

Commit

Permalink
Add isSealed check to is-es-module.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed May 23, 2018
1 parent e2c7132 commit 5983a6d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/sinon/util/core/is-es-module.js
Expand Up @@ -11,6 +11,7 @@ module.exports = function (object) {
return (
object &&
typeof Symbol !== "undefined" &&
object[Symbol.toStringTag] === "Module"
object[Symbol.toStringTag] === "Module" &&
Object.isSealed(object)
);
};
4 changes: 4 additions & 0 deletions test/es2015/a-module-with-to-string-tag.mjs
@@ -0,0 +1,4 @@
export default {
[Symbol.toStringTag]: "Module",
anExport() { return 42; }
};
7 changes: 7 additions & 0 deletions test/es2015/module-support-assessment-test.mjs
@@ -1,6 +1,7 @@
import referee from "@sinonjs/referee";
import sinon from "../../lib/sinon";
import * as aModule from "./a-module";
import aModuleWithToStringTag from "./a-module-with-to-string-tag";
import aModuleWithDefaultExport from "./a-module-with-default";

// Usually one would import the default module, but one can make a form of wrapper like this
Expand All @@ -26,6 +27,12 @@ function createTestSuite(action) {
});
});

it("should NOT result in error with a custom toStringTag", function () {
refute.exception(function () {
stub = sinon[action](aModuleWithToStringTag, "anExport");
});
});

it("should spy/stub an exported function", function () {
stub = sinon[action](aModuleWithDefaultExport, "anExport");
aModuleWithDefaultExport.anExport();
Expand Down

0 comments on commit 5983a6d

Please sign in to comment.