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:
authorjeroenvalcke <valcke_jeroen@hotmail.com>2017-11-13 19:43:47 +0300
committerjeroenvalcke <valcke_jeroen@hotmail.com>2017-11-13 19:43:47 +0300
commit0a77533c6b7a41606975303be2327c250cd77d19 (patch)
tree58b7025a7f49f19d8015720601410c857eeaf495 /testLib
parentc176d025b57ff616d2a63989a685fe70651e33d3 (diff)
parentcce2de832c99e1f1491c9766bc6a2f1b4d0a3bd2 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'testLib')
-rw-r--r--testLib/constModule.js (renamed from testLib/ES2015Module.js)7
-rw-r--r--testLib/sharedTestCases.js59
-rw-r--r--testLib/throwError.js5
3 files changed, 23 insertions, 48 deletions
diff --git a/testLib/ES2015Module.js b/testLib/constModule.js
index 81eba2b..77396d9 100644
--- a/testLib/ES2015Module.js
+++ b/testLib/constModule.js
@@ -1,14 +1,13 @@
-
const someOtherModule = require("./someOtherModule");
const language = "nl";
-module.exports.getLang = () => {
+exports.getLang = () => {
return language;
-}
+};
exports.getOtherModuleName = () => {
return someOtherModule.name;
-}
+};
exports.filename = __filename;
exports.dirname = __dirname;
diff --git a/testLib/sharedTestCases.js b/testLib/sharedTestCases.js
index ddb8b04..b6caf6a 100644
--- a/testLib/sharedTestCases.js
+++ b/testLib/sharedTestCases.js
@@ -17,7 +17,7 @@ function checkForTypeError(err) {
expect(err.constructor).to.be(TypeError);
}
-describe("rewire " + (typeof testEnv === "undefined"? "(node)": "(" + testEnv + ")"), function () {
+module.exports = function () {
it("should work like require()", function () {
rewire("./moduleA.js").getFilename();
@@ -265,7 +265,7 @@ describe("rewire " + (typeof testEnv === "undefined"? "(node)": "(" + testEnv +
throwError();
} catch (err) {
if (err.stack) {
- expect(err.stack.split("\n")[1]).to.match(/:2:11/);
+ expect(err.stack.split("\n")[1]).to.match(/:7:11/);
}
}
});
@@ -372,51 +372,22 @@ describe("rewire " + (typeof testEnv === "undefined"? "(node)": "(" + testEnv +
revert();
});
- it("Should be possible to mock a const variable using __with__ syntax", function() {
- var ES2015Module = rewire("./ES2015Module", {
- convertConst: true
- });
-
- ES2015Module.__with__({
- language: "en"
- })(function() {
- expect(ES2015Module.getLang()).to.equal("en");
- expect(ES2015Module.getOtherModuleName()).to.equal("somOtherModule");
- });
- });
+ it("should be possible to mock a set a const variable using __set__ syntax", function() {
+ var constModule = rewire("./constModule");
- it("Should be possible to mock a const required variable using __with__ syntax", function() {
- var ES2015Module = rewire("./ES2015Module", {
- convertConst: true
+ constModule.__set__("language", "de");
+ constModule.__set__("someOtherModule", {
+ name: "differentModule"
});
-
- ES2015Module.__with__({
- someOtherModule: {
- name: "mocked"
- }
- })(function() {
- expect(ES2015Module.getLang()).to.equal("nl");
- expect(ES2015Module.getOtherModuleName()).to.equal("mocked");
- });
- });
-
- it("Should be possible to mock a set a const variable using __set__ syntax", function() {
- var ES2015Module = rewire("./ES2015Module", {
- convertConst: true
- });
-
- ES2015Module.__set__("language", "de");
-
- expect(ES2015Module.getLang()).to.equal("de");
-
- ES2015Module.__set__("language", "nl");
-
- expect(ES2015Module.getLang()).to.equal("nl");
+ expect(constModule.getLang()).to.equal("de");
+ expect(constModule.getOtherModuleName()).to.equal("differentModule");
})
- it("Should have correct __filename and __dirname when mocked using convertConst", function() {
- expect(rewire("./ES2015Module", { convertConst: true }).filename).to.equal(require("./ES2015Module").filename);
- expect(rewire("./ES2015Module", { convertConst: true }).dirname).to.equal(require("./ES2015Module").dirname);
+ 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);
});
-});
+};
diff --git a/testLib/throwError.js b/testLib/throwError.js
index 9bdf68b..ffb6a71 100644
--- a/testLib/throwError.js
+++ b/testLib/throwError.js
@@ -1,3 +1,8 @@
+// Using const here because we know that Babel will transform that part
+const test = 1;
+
module.exports = function () {
+ let test = 1;
+
throw new Error();
};