-
Notifications
You must be signed in to change notification settings - Fork 21
/
is-map.test.js
186 lines (170 loc) · 5.74 KB
/
is-map.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
"use strict";
var assert = require("assert");
var referee = require("../referee");
var captureArgs = require("../test-helper/capture-args");
describe("assert.isMap", function() {
it("should pass for Map", function() {
referee.assert.isMap(new Map());
});
it("should fail for String", function() {
assert.throws(
function() {
referee.assert.isMap("apple pie");
},
function(error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
"[assert.isMap] Expected apple pie to be a Map"
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "assert.isMap");
return true;
}
);
});
it("should fail for Array", function() {
assert.throws(
function() {
referee.assert.isMap([]);
},
function(error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
"[assert.isMap] Expected [] to be a Map"
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "assert.isMap");
return true;
}
);
});
it("should fail for WeakMap", function() {
assert.throws(
function() {
// eslint-disable-next-line ie11/no-weak-collections
referee.assert.isMap(new WeakMap());
},
function(error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
"[assert.isMap] Expected [WeakMap] { } to be a Map"
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "assert.isMap");
return true;
}
);
});
it("should fail for Object", function() {
assert.throws(
function() {
referee.assert.isMap({});
},
function(error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
"[assert.isMap] Expected { } to be a Map"
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "assert.isMap");
return true;
}
);
});
it("should fail for arguments", function() {
assert.throws(
function() {
referee.assert.isMap(captureArgs());
},
function(error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
"[assert.isMap] Expected { } to be a Map"
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "assert.isMap");
return true;
}
);
});
it("should fail with custom message", function() {
var message = "4eb2174d-3faa-4095-92d1-cd8dfb7e2a58";
assert.throws(
function() {
referee.assert.isMap("apple pie", message);
},
function(error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
"[assert.isMap] " +
message +
": Expected apple pie to be a Map"
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "assert.isMap");
return true;
}
);
});
});
describe("refute.isMap", function() {
it("should fail for Map", function() {
assert.throws(
function() {
referee.refute.isMap(new Map());
},
function(error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
"[refute.isMap] Expected Map [] not to be a Map"
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "refute.isMap");
return true;
}
);
});
it("should pass for String", function() {
referee.refute.isMap("apple pie");
});
it("should pass for Array", function() {
referee.refute.isMap([]);
});
it("should pass for WeakMap", function() {
// eslint-disable-next-line ie11/no-weak-collections
referee.refute.isMap(new WeakMap());
});
it("should pass for Object", function() {
referee.refute.isMap({});
});
it("should pass for arguments", function() {
referee.refute.isMap(captureArgs());
});
it("should fail with custom message", function() {
var message = "f84e51dd-d5af-4ef0-81ec-2d575eadd735";
assert.throws(
function() {
referee.refute.isMap(new Map(), message);
},
function(error) {
assert.equal(error.code, "ERR_ASSERTION");
assert.equal(
error.message,
"[refute.isMap] " +
message +
": Expected Map [] not to be a Map"
);
assert.equal(error.name, "AssertionError");
assert.equal(error.operator, "refute.isMap");
return true;
}
);
});
});