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:
authorJohannes <johannes.ewald@roomieplanet.de>2012-07-10 22:32:54 +0400
committerJohannes <johannes.ewald@roomieplanet.de>2012-07-10 22:32:54 +0400
commit0bb70adf091ce5ccf8c81f28cc72a229ac15eba1 (patch)
tree61ef88ea9646dd734533e295d7002653c311508e /test/__set__.test.js
parentb443c61ab73679410f083e383be7aef3039d228f (diff)
- fixed parsing error when trying to set a function as mockv0.3.2
- update to mocha 1.3.x - fixed minor IE issues
Diffstat (limited to 'test/__set__.test.js')
-rw-r--r--test/__set__.test.js206
1 files changed, 103 insertions, 103 deletions
diff --git a/test/__set__.test.js b/test/__set__.test.js
index 85a1d37..7b9c2cb 100644
--- a/test/__set__.test.js
+++ b/test/__set__.test.js
@@ -1,104 +1,104 @@
-var expect = require("expect.js"),
- __set__ = require("../lib/__set__.js"),
- vm = require("vm"),
-
- expectReferenceError = expectError(ReferenceError),
- expectTypeError = expectError(TypeError);
-
-function expectError(ErrConstructor) {
- return function expectReferenceError(err) {
- expect(err.constructor.name === ErrConstructor.name).to.be(true);
- };
-}
-
-describe("__set__", function () {
- var moduleFake;
-
- beforeEach(function () {
- moduleFake = {
- myNumber: 0, // copy by value
- myObj: {}, // copy by reference
-
- // these variables are used within the set method
- // because there is a eval() statement within the set method
- // these variables should not override same-named vars of the module
- key: "key",
- env: "env",
- src: "src"
- };
-
- vm.runInNewContext(
- "__set__ = " + __set__.toString() + "; " +
- "getNumber = function () { return myNumber; }; " +
- "getObj = function () { return myObj; }; ",
- moduleFake
- );
- });
- it("should set the new number when calling with varName, varValue", function () {
- expect(moduleFake.getNumber() === 0).to.be(true);
- moduleFake.__set__("myNumber", 2);
- expect(moduleFake.getNumber() === 2).to.be(true);
- });
- it("should set the new object when calling with varName, varValue", function () {
- var newObj = { hello: "hello" };
-
- expect(moduleFake.getObj()).to.eql({});
- moduleFake.__set__("myObj", newObj);
- expect(moduleFake.getObj() === newObj).to.be(true);
- });
- it("should set the new number and the new obj when calling with an env-obj", function () {
- var newObj = { hello: "hello" };
-
- expect(moduleFake.getNumber() === 0).to.be(true);
- expect(moduleFake.getObj()).to.eql({});
- moduleFake.__set__({
- myNumber: 2,
- myObj: newObj
- });
- expect(moduleFake.getNumber() === 2).to.be(true);
- expect(moduleFake.getObj() === newObj).to.be(true);
- });
- it("should return undefined", function () {
- expect(moduleFake.__set__("myNumber", 4) === undefined).to.be(true);
- });
- it("should throw a ReferenceError when trying to set non-existing vars", function () {
- expect(function () {
- moduleFake.__set__("notExisting", 3);
- }).to.throwException();
- expect(function () {
- moduleFake.__set__({
- notExisting: "bla",
- notExistingAsWell: "blabla"
- });
- }).to.throwException(expectReferenceError);
- });
- it("should throw a TypeError when passing misfitting params", function () {
- expect(function () {
- moduleFake.__set__();
- }).to.throwException(expectTypeError);
- expect(function () {
- moduleFake.__set__(undefined);
- }).to.throwException(expectTypeError);
- expect(function () {
- moduleFake.__set__(null);
- }).to.throwException(expectTypeError);
- expect(function () {
- moduleFake.__set__(true);
- }).to.throwException(expectTypeError);
- expect(function () {
- moduleFake.__set__(2);
- }).to.throwException(expectTypeError);
- expect(function () {
- moduleFake.__set__("");
- }).to.throwException(expectTypeError);
- expect(function () {
- moduleFake.__set__(function () {});
- }).to.throwException(expectTypeError);
- expect(function () {
- moduleFake.__set__({}, true); // misfitting number of params
- }).to.throwException(expectTypeError);
- expect(function () {
- moduleFake.__set__("someVar"); // misfitting number of params
- }).to.throwException(expectTypeError);
- });
+var expect = require("expect.js"),
+ __set__ = require("../lib/__set__.js"),
+ vm = require("vm"),
+
+ expectReferenceError = expectError(ReferenceError),
+ expectTypeError = expectError(TypeError);
+
+function expectError(ErrConstructor) {
+ return function expectReferenceError(err) {
+ expect(err.constructor.name).to.be(ErrConstructor.name);
+ };
+}
+
+describe("__set__", function () {
+ var moduleFake;
+
+ beforeEach(function () {
+ moduleFake = {
+ myValue: 0, // copy by value
+ myReference: {} // copy by reference
+ };
+
+ vm.runInNewContext(
+ "__set__ = " + __set__.toString() + "; " +
+ "getValue = function () { return myValue; }; " +
+ "getReference = function () { return myReference; }; ",
+ moduleFake
+ );
+ });
+ it("should set the new value when calling with varName, varValue", function () {
+ expect(moduleFake.getValue()).to.be(0);
+ moduleFake.__set__("myValue", undefined);
+ expect(moduleFake.getValue()).to.be(undefined);
+ moduleFake.__set__("myValue", null);
+ expect(moduleFake.getValue()).to.be(null);
+ moduleFake.__set__("myValue", 2);
+ expect(moduleFake.getValue()).to.be(2);
+ moduleFake.__set__("myValue", "hello");
+ expect(moduleFake.getValue()).to.be("hello");
+ });
+ it("should set the new reference when calling with varName, varValue", function () {
+ var newObj = { hello: "hello" },
+ newArr = [1, 2, 3],
+ regExp = /123/gi;
+
+ function newFn() {
+ console.log("hello");
+ }
+
+ expect(moduleFake.getReference()).to.eql({});
+ moduleFake.__set__("myReference", newObj);
+ expect(moduleFake.getReference()).to.be(newObj);
+ moduleFake.__set__("myReference", newArr);
+ expect(moduleFake.getReference()).to.be(newArr);
+ moduleFake.__set__("myReference", newFn);
+ expect(moduleFake.getReference()).to.be(newFn);
+ moduleFake.__set__("myReference", regExp);
+ expect(moduleFake.getReference()).to.be(regExp);
+ });
+ it("should set the new number and the new obj when calling with an env-obj", function () {
+ var newObj = { hello: "hello" };
+
+ expect(moduleFake.getValue()).to.be(0);
+ expect(moduleFake.getReference()).to.eql({});
+ moduleFake.__set__({
+ myValue: 2,
+ myReference: newObj
+ });
+ expect(moduleFake.getValue()).to.be(2);
+ expect(moduleFake.getReference()).to.be(newObj);
+ });
+ it("should return undefined", function () {
+ expect(moduleFake.__set__("myValue", 4)).to.be(undefined);
+ });
+ it("should throw a TypeError when passing misfitting params", function () {
+ expect(function () {
+ moduleFake.__set__();
+ }).to.throwException(expectTypeError);
+ expect(function () {
+ moduleFake.__set__(undefined);
+ }).to.throwException(expectTypeError);
+ expect(function () {
+ moduleFake.__set__(null);
+ }).to.throwException(expectTypeError);
+ expect(function () {
+ moduleFake.__set__(true);
+ }).to.throwException(expectTypeError);
+ expect(function () {
+ moduleFake.__set__(2);
+ }).to.throwException(expectTypeError);
+ expect(function () {
+ moduleFake.__set__("");
+ }).to.throwException(expectTypeError);
+ expect(function () {
+ moduleFake.__set__(function () {});
+ }).to.throwException(expectTypeError);
+ expect(function () {
+ moduleFake.__set__({}, true); // misfitting number of params
+ }).to.throwException(expectTypeError);
+ expect(function () {
+ moduleFake.__set__("someVar"); // misfitting number of params
+ }).to.throwException(expectTypeError);
+ });
}); \ No newline at end of file