Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/rewire.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'testLib/sharedTestCases.js')
-rw-r--r--testLib/sharedTestCases.js71
1 files changed, 41 insertions, 30 deletions
diff --git a/testLib/sharedTestCases.js b/testLib/sharedTestCases.js
index b6caf6a..6cd9b2e 100644
--- a/testLib/sharedTestCases.js
+++ b/testLib/sharedTestCases.js
@@ -13,6 +13,23 @@ var expect = require("expect.js"),
__get__Src = require("../lib/__get__.js").toString(),
__with__Src = require("../lib/__with__.js").toString();
+var supportsObjectSpread = (function () {
+ try {
+ eval("({...{}})");
+ return true;
+ } catch (err) {
+ return false;
+ }
+})();
+var supportsObjectRest = (function () {
+ try {
+ eval("const {...a} = {}");
+ return true;
+ } catch (err) {
+ return false;
+ }
+})();
+
function checkForTypeError(err) {
expect(err.constructor).to.be(TypeError);
}
@@ -220,22 +237,24 @@ module.exports = function () {
expect(rewired.__get__("someVar")).to.be("hello");
});
- 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 a boolean", function( ) {
+ rewire("./boolean.js"); // should not throw
+ });
+
+ it("should not be a problem to have a module that exports null", function () {
+ rewire("./null.js"); // should not throw
});
- 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 () {
+ rewire("./sealedObject.js"); // should not throw
});
- 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();
+ (supportsObjectSpread ? it : it.skip)("should not be a problem to have a module that uses object spread operator", function () {
+ rewire("./objectSpreadOperator.js"); // should not throw
+ });
+
+ (supportsObjectRest ? it : it.skip)("should not be a problem to have a module that uses object rest operator", function () {
+ rewire("./objectRestOperator.js"); // should not throw
});
it("should not influence the original require if nothing has been required within the rewired module", function () {
@@ -258,15 +277,10 @@ module.exports = function () {
it("should not modify line numbers in stack traces", function () {
var throwError = rewire("./throwError.js");
- if (process.env.running_under_istanbul === "1") {
- return;
- }
try {
throwError();
} catch (err) {
- if (err.stack) {
- expect(err.stack.split("\n")[1]).to.match(/:7:11/);
- }
+ expect(err.stack.split("\n")[1]).to.match(/:6:26/);
}
});
@@ -372,22 +386,19 @@ module.exports = function () {
revert();
});
- it("should be possible to mock a set a const variable using __set__ syntax", function() {
+ it("should be possible to set a const variable", function () {
var constModule = rewire("./constModule");
- constModule.__set__("language", "de");
- constModule.__set__("someOtherModule", {
- name: "differentModule"
+ "abcdefghij".split("").forEach(letter => {
+ constModule.__set__(letter, "this has been changed"); // should not throw
+ expect(constModule[letter]()).to.equal("this has been changed");
});
- expect(constModule.getLang()).to.equal("de");
- expect(constModule.getOtherModuleName()).to.equal("differentModule");
- })
-
- it("should have correct __filename and __dirname when mocked using convertConst", function() {
- var constModule = rewire("./constModule");
+ });
- expect(constModule.filename).to.equal(require("./constModule").filename);
- expect(constModule.dirname).to.equal(require("./constModule").dirname);
+ it("should fail with a helpful TypeError when const is re-assigned", function () {
+ expect(function () {
+ rewire("./wrongConstModule");
+ }).to.throwException(/^Assignment to constant variable at .+?wrongConstModule\.js:4:1$/);
});
};