-
Notifications
You must be signed in to change notification settings - Fork 21
/
same.test.js
132 lines (109 loc) · 4.12 KB
/
same.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
"use strict";
var assert = require("assert");
var proxyquire = require("proxyquire").noCallThru();
var sinon = require("sinon");
var obj = { id: 42 };
var obj2 = { id: 42 };
describe("same factory", function() {
beforeEach(function() {
this.fakeActualAndExpectedMessageValues =
"866c5b01-0028-4cf2-8dd7-9ef99bbc53b0";
var factory = proxyquire("./same", {
"../actual-and-expected-message-values": this
.fakeActualAndExpectedMessageValues
});
this.fakeReferee = {
add: sinon.fake()
};
factory(this.fakeReferee);
this.options = this.fakeReferee.add.args[0][1];
});
it("calls referee.add with 'same' as name", function() {
assert(this.fakeReferee.add.calledWith("same"));
});
describe(".assert", function() {
context("when comparing object to itself", function() {
it("returns true", function() {
assert(this.options.assert(obj, obj));
});
});
context("when comparing strings", function() {
it("returns true", function() {
assert(this.options.assert("Hey", "Hey"));
});
});
context("when comparing booleans", function() {
it("returns true", function() {
assert(this.options.assert(true, true));
assert(this.options.assert(false, false));
});
});
context("when comparing Infinity", function() {
it("returns true", function() {
assert(this.options.assert(Infinity, Infinity));
});
});
context("when comparing numbers", function() {
it("returns true", function() {
assert(this.options.assert(32, 32));
});
});
context("when comparing null with null", function() {
it("returns true", function() {
assert(this.options.assert(null, null));
});
});
context("when comparing undefined with undefined", function() {
it("returns true", function() {
assert(this.options.assert(undefined, undefined));
});
});
context("when comparing NaN with NaN", function() {
it("returns true", function() {
assert(this.options.assert(NaN, NaN));
});
});
context("when comparing different objects", function() {
it("returns false", function() {
assert.equal(this.options.assert(obj, obj2), false);
});
});
context("when comparing without coercion", function() {
it("returns false", function() {
assert.equal(this.options.assert(666, "666"), false);
assert.equal(this.options.assert("666", 666), false);
});
});
context("when comparing -0 to +0", function() {
it("returns false", function() {
assert.equal(this.options.assert(-0, +0), false);
});
});
});
describe(".assertMessage", function() {
it("is '${customMessage}${actual} expected to be the same object as ${expected}'", function() {
assert.equal(
this.options.assertMessage,
"${customMessage}${actual} expected to be the same object as ${expected}"
);
});
});
describe(".refuteMessage", function() {
it("is '${customMessage}${actual} expected not to be the same object as ${expected}'", function() {
assert.equal(
this.options.refuteMessage,
"${customMessage}${actual} expected not to be the same object as ${expected}"
);
});
});
describe(".expectation", function() {
it("is 'toBe'", function() {
assert.equal(this.options.expectation, "toBe");
});
});
describe(".values", function() {
it("delegates to '../actual-and-expected-message-values'", function() {
assert.equal(this.options.values, this.fakeActualAndExpectedMessageValues);
});
});
});