-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpect.js
More file actions
40 lines (34 loc) · 922 Bytes
/
expect.js
File metadata and controls
40 lines (34 loc) · 922 Bytes
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
/* eslint-env mocha, browser */
exports.expect = function expect(v) {
function assert(isEqual, other) {
if (!isEqual) {
const got = JSON.stringify(v);
const want = JSON.stringify(other);
throw new Error("expected " + got + " to equal " + want);
}
}
function equal(other) {
assert(v === other, other);
}
function deepEqual(other) {
if (v === other) {
return;
}
assert(!v === !other);
if (typeof v !== "object" || v === null) {
assert(false, other);
}
assert(typeof other === "object" && other !== null, other);
for (let key in v) {
if (v.hasOwnProperty(key)) {
expect(v[key]).to.deep.equal(other[key]);
}
}
for (let key in other) {
if (other.hasOwnProperty(key)) {
expect(v.hasOwnProperty(key)).to.equal(true);
}
}
}
return { to: { equal: equal, deep: { equal: deepEqual } } };
};