Skip to content

Commit 9ced991

Browse files
JoshuaGramsljharb
authored andcommitted
[Fix] notEqual and notDeepEqual show "expected" value on failure
Fixes #453.
1 parent 75c467e commit 9ced991

File tree

3 files changed

+260
-2
lines changed

3 files changed

+260
-2
lines changed

lib/test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ function notEqual(a, b, msg, extra) {
402402
message : defined(msg, 'should not be equal'),
403403
operator : 'notEqual',
404404
actual : a,
405-
notExpected : b,
405+
expected : b,
406406
extra : extra
407407
});
408408
}
@@ -451,7 +451,7 @@ function notDeepEqual(a, b, msg, extra) {
451451
message : defined(msg, 'should not be equivalent'),
452452
operator : 'notDeepEqual',
453453
actual : a,
454-
notExpected : b,
454+
expected : b,
455455
extra : extra
456456
});
457457
}

test/not-deep-equal-failure.js

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
var tape = require('../');
2+
var tap = require('tap');
3+
var concat = require('concat-stream');
4+
var tapParser = require('tap-parser');
5+
var common = require('./common');
6+
7+
var getDiag = common.getDiag;
8+
var stripFullStack = common.stripFullStack;
9+
10+
tap.test('deep equal failure', function (assert) {
11+
var test = tape.createHarness({ exit : false });
12+
var stream = test.createStream();
13+
var parser = tapParser();
14+
assert.plan(3);
15+
16+
stream.pipe(parser);
17+
stream.pipe(concat(function (body) {
18+
assert.equal(
19+
stripFullStack(body.toString('utf8')),
20+
'TAP version 13\n'
21+
+ '# not deep equal\n'
22+
+ 'not ok 1 should not be equivalent\n'
23+
+ ' ---\n'
24+
+ ' operator: notDeepEqual\n'
25+
+ ' expected: |-\n'
26+
+ ' { b: 2 }\n'
27+
+ ' actual: |-\n'
28+
+ ' { b: 2 }\n'
29+
+ ' at: Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n'
30+
+ ' stack: |-\n'
31+
+ ' Error: should not be equivalent\n'
32+
+ ' [... stack stripped ...]\n'
33+
+ ' at Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n'
34+
+ ' [... stack stripped ...]\n'
35+
+ ' ...\n'
36+
+ '\n'
37+
+ '1..1\n'
38+
+ '# tests 1\n'
39+
+ '# pass 0\n'
40+
+ '# fail 1\n'
41+
);
42+
43+
assert.deepEqual(getDiag(body), {
44+
operator: 'notDeepEqual',
45+
expected: '{ b: 2 }',
46+
actual: '{ b: 2 }'
47+
});
48+
}));
49+
50+
parser.once('assert', function (data) {
51+
delete data.diag.stack;
52+
delete data.diag.at;
53+
assert.deepEqual(data, {
54+
ok: false,
55+
id: 1,
56+
name: 'should not be equivalent',
57+
diag: {
58+
operator: 'notDeepEqual',
59+
expected: '{ b: 2 }',
60+
actual: '{ b: 2 }'
61+
}
62+
});
63+
});
64+
65+
test("not deep equal", function (t) {
66+
t.plan(1);
67+
t.notDeepEqual({b: 2}, {b: 2});
68+
});
69+
})
70+
71+
tap.test('not deep equal failure, depth 6, with option', function (assert) {
72+
var test = tape.createHarness({ exit : false });
73+
var stream = test.createStream();
74+
var parser = tapParser();
75+
assert.plan(3);
76+
77+
stream.pipe(parser);
78+
stream.pipe(concat(function (body) {
79+
assert.equal(
80+
stripFullStack(body.toString('utf8')),
81+
'TAP version 13\n'
82+
+ '# not deep equal\n'
83+
+ 'not ok 1 should not be equivalent\n'
84+
+ ' ---\n'
85+
+ ' operator: notDeepEqual\n'
86+
+ ' expected: |-\n'
87+
+ ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }\n'
88+
+ ' actual: |-\n'
89+
+ ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }\n'
90+
+ ' at: Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n'
91+
+ ' stack: |-\n'
92+
+ ' Error: should not be equivalent\n'
93+
+ ' [... stack stripped ...]\n'
94+
+ ' at Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n'
95+
+ ' [... stack stripped ...]\n'
96+
+ ' ...\n'
97+
+ '\n'
98+
+ '1..1\n'
99+
+ '# tests 1\n'
100+
+ '# pass 0\n'
101+
+ '# fail 1\n'
102+
);
103+
104+
assert.deepEqual(getDiag(body), {
105+
operator: 'notDeepEqual',
106+
expected: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }',
107+
actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }'
108+
});
109+
}));
110+
111+
parser.once('assert', function (data) {
112+
delete data.diag.stack;
113+
delete data.diag.at;
114+
assert.deepEqual(data, {
115+
ok: false,
116+
id: 1,
117+
name: 'should not be equivalent',
118+
diag: {
119+
operator: 'notDeepEqual',
120+
expected: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }',
121+
actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }'
122+
}
123+
});
124+
});
125+
126+
test("not deep equal", {objectPrintDepth: 6}, function (t) {
127+
t.plan(1);
128+
t.notDeepEqual({ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }, { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } });
129+
});
130+
})
131+
132+
tap.test('not deep equal failure, depth 6, without option', function (assert) {
133+
var test = tape.createHarness({ exit : false });
134+
var stream = test.createStream();
135+
var parser = tapParser();
136+
assert.plan(3);
137+
138+
stream.pipe(parser);
139+
stream.pipe(concat(function (body) {
140+
assert.equal(
141+
stripFullStack(body.toString('utf8')),
142+
'TAP version 13\n'
143+
+ '# not deep equal\n'
144+
+ 'not ok 1 should not be equivalent\n'
145+
+ ' ---\n'
146+
+ ' operator: notDeepEqual\n'
147+
+ ' expected: |-\n'
148+
+ ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n'
149+
+ ' actual: |-\n'
150+
+ ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n'
151+
+ ' at: Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n'
152+
+ ' stack: |-\n'
153+
+ ' Error: should not be equivalent\n'
154+
+ ' [... stack stripped ...]\n'
155+
+ ' at Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n'
156+
+ ' [... stack stripped ...]\n'
157+
+ ' ...\n'
158+
+ '\n'
159+
+ '1..1\n'
160+
+ '# tests 1\n'
161+
+ '# pass 0\n'
162+
+ '# fail 1\n'
163+
);
164+
165+
assert.deepEqual(getDiag(body), {
166+
operator: 'notDeepEqual',
167+
expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }',
168+
actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }'
169+
});
170+
}));
171+
172+
parser.once('assert', function (data) {
173+
delete data.diag.stack;
174+
delete data.diag.at;
175+
assert.deepEqual(data, {
176+
ok: false,
177+
id: 1,
178+
name: 'should not be equivalent',
179+
diag: {
180+
operator: 'notDeepEqual',
181+
expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }',
182+
actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }'
183+
}
184+
});
185+
});
186+
187+
test("not deep equal", function (t) {
188+
t.plan(1);
189+
t.notDeepEqual({ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }, { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } });
190+
});
191+
})

test/not-equal-failure.js

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
var tape = require('../');
2+
var tap = require('tap');
3+
var concat = require('concat-stream');
4+
var tapParser = require('tap-parser');
5+
var common = require('./common');
6+
7+
var getDiag = common.getDiag;
8+
var stripFullStack = common.stripFullStack;
9+
10+
tap.test('not equal failure', function (assert) {
11+
var test = tape.createHarness({ exit : false });
12+
var stream = test.createStream();
13+
var parser = tapParser();
14+
assert.plan(3);
15+
16+
stream.pipe(parser);
17+
stream.pipe(concat(function (body) {
18+
assert.equal(
19+
stripFullStack(body.toString('utf8')),
20+
'TAP version 13\n'
21+
+ '# not equal\n'
22+
+ 'not ok 1 should not be equal\n'
23+
+ ' ---\n'
24+
+ ' operator: notEqual\n'
25+
+ ' expected: 2\n'
26+
+ ' actual: 2\n'
27+
+ ' at: Test.<anonymous> ($TEST/not-equal-failure.js:$LINE:$COL)\n'
28+
+ ' stack: |-\n'
29+
+ ' Error: should not be equal\n'
30+
+ ' [... stack stripped ...]\n'
31+
+ ' at Test.<anonymous> ($TEST/not-equal-failure.js:$LINE:$COL)\n'
32+
+ ' [... stack stripped ...]\n'
33+
+ ' ...\n'
34+
+ '\n'
35+
+ '1..1\n'
36+
+ '# tests 1\n'
37+
+ '# pass 0\n'
38+
+ '# fail 1\n'
39+
);
40+
41+
assert.deepEqual(getDiag(body), {
42+
operator: 'notEqual',
43+
expected: '2',
44+
actual: '2'
45+
});
46+
}));
47+
48+
parser.once('assert', function (data) {
49+
delete data.diag.stack;
50+
delete data.diag.at;
51+
assert.deepEqual(data, {
52+
ok: false,
53+
id: 1,
54+
name: 'should not be equal',
55+
diag: {
56+
operator: 'notEqual',
57+
expected: '2',
58+
actual: '2'
59+
}
60+
});
61+
});
62+
63+
test("not equal", function (t) {
64+
t.plan(1);
65+
t.notEqual(2, 2);
66+
});
67+
})

0 commit comments

Comments
 (0)