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
path: root/test
diff options
context:
space:
mode:
authorJohannes Ewald <johannes.ewald@peerigon.com>2014-07-08 03:37:32 +0400
committerJohannes Ewald <johannes.ewald@peerigon.com>2014-07-08 03:37:32 +0400
commitd044f04e4c6a5e9bff37c384a2256d771aa0e5bc (patch)
tree5ec6fee85914bb91fe76e1911fd2ee204d5e595c /test
parent3f7b23aec53d97bed6489f3be9ad3954bc629b7d (diff)
Improve __with__ tests
Diffstat (limited to 'test')
-rw-r--r--test/__with__.test.js32
1 files changed, 26 insertions, 6 deletions
diff --git a/test/__with__.test.js b/test/__with__.test.js
index 7ce86b5..532ef91 100644
--- a/test/__with__.test.js
+++ b/test/__with__.test.js
@@ -1,7 +1,9 @@
var expect = require("expect.js"),
__with__ = require("../lib/__with__.js"),
__set__ = require("../lib/__set__.js"),
- vm = require("vm");
+ vm = require("vm"),
+
+ expectTypeError = expectError(TypeError);
function expectError(ErrConstructor) {
return function expectReferenceError(err) {
@@ -41,7 +43,7 @@ describe("__with__", function() {
})).to.be.a("function");
});
- it("should return a function that can be invoked with a callback which guarantees __sets__ undo function is called for you at the end", function () {
+ it("should return a function that can be invoked with a callback which guarantees __set__'s undo function is called for you at the end", function () {
expect(moduleFake.getValue()).to.be(0);
expect(moduleFake.getReference()).to.eql({});
@@ -59,6 +61,24 @@ describe("__with__", function() {
expect(moduleFake.getReference()).to.eql({});
});
+ it("should also accept a variable name and a variable value (just like __set__)", function () {
+ expect(moduleFake.getValue()).to.be(0);
+
+ moduleFake.__with__("myValue", 2)(function () {
+ expect(moduleFake.getValue()).to.be(2);
+ });
+
+ expect(moduleFake.getValue()).to.be(0);
+
+ expect(moduleFake.getReference()).to.eql({});
+
+ moduleFake.__with__("myReference", newObj)(function () {
+ expect(moduleFake.getReference()).to.be(newObj);
+ });
+
+ expect(moduleFake.getReference()).to.eql({});
+ });
+
it("should still revert values if the callback throws an exception", function(){
expect(function withError() {
moduleFake.__with__({
@@ -86,9 +106,9 @@ describe("__with__", function() {
};
}
- expect(callWithFunction(1)).to.throwError();
- expect(callWithFunction("a string")).to.throwError();
- expect(callWithFunction({})).to.throwError();
- expect(callWithFunction(function(){})).to.not.throwError();
+ expect(callWithFunction(1)).to.throwError(expectTypeError);
+ expect(callWithFunction("a string")).to.throwError(expectTypeError);
+ expect(callWithFunction({})).to.throwError(expectTypeError);
+ expect(callWithFunction(function(){})).to.not.throwError(expectTypeError);
});
});