Skip to content

Commit

Permalink
Add new keyword to inspection so it outputs valid code.
Browse files Browse the repository at this point in the history
This aligns the Map plugin with commit bf45b95 in unexpected-set.
  • Loading branch information
alexjeffburke committed Mar 2, 2021
1 parent 2eaf73e commit 18efc34
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 62 deletions.
2 changes: 1 addition & 1 deletion lib/unexpectedMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function createUnexpectedMap(expect) {
);
},
prefix(output, obj) {
return output.text('Map([');
return output.jsKeyword('new').sp().jsKeyword('Map').text('[');
},
property(output, key, inspectedValue) {
return output.propertyForMap(key, inspectedValue);
Expand Down
4 changes: 2 additions & 2 deletions test/assertions/Map.to-be-empty.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('to be empty assertion', () => {
},
'to throw an error satisfying',
'to equal snapshot',
"expected Map([ [1, 'foo'], [2, 'bar'], [3, 'baz'] ]) to be empty"
"expected new Map[ [1, 'foo'], [2, 'bar'], [3, 'baz'] ]) to be empty"
);
});

Expand All @@ -40,7 +40,7 @@ describe('to be empty assertion', () => {
},
'to throw an error satisfying',
'to equal snapshot',
'expected Map([]) not to be empty'
'expected new Map[]) not to be empty'
);
});
});
8 changes: 4 additions & 4 deletions test/assertions/Map.to-equal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ describe('to equal assertion', function () {
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([ [{}, 123] ]) to equal Map([ [{}, 123] ])
expected new Map[ [{}, 123] ]) to equal new Map[ [{}, 123] ])
Map([
new Map[
[{}, 123] // should be removed
// missing [{}, 123]
])
Expand All @@ -32,9 +32,9 @@ describe('to equal assertion', function () {
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([ [123, {}] ]) to equal Map([ [123, {}] ])
expected new Map[ [123, {}] ]) to equal new Map[ [123, {}] ])
Map([
new Map[
[123, {
}]
Expand Down
4 changes: 2 additions & 2 deletions test/assertions/Map.to-have-size.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('to have size assertion', () => {
},
'to throw an error satisfying',
'to equal snapshot',
"expected Map([ ['foo', 'bar'] ]) to have size 2"
"expected new Map[ ['foo', 'bar'] ]) to have size 2"
);
});

Expand All @@ -26,7 +26,7 @@ describe('to have size assertion', () => {
},
'to throw an error satisfying',
'to equal snapshot',
"expected Map([ ['foo', 'bar'] ]) not to have size 1"
"expected new Map[ ['foo', 'bar'] ]) not to have size 1"
);
});
});
10 changes: 5 additions & 5 deletions test/assertions/Map.to-have-values-satisfying.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ describe('to have values satisfying assertion', function () {
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([]) to have values satisfying
expected new Map[]) to have values satisfying
expect.it((value) => {
expect(value, 'to equal', '0');
})
expected Map([]) not to be empty
expected new Map[]) not to be empty
`
);
});
Expand All @@ -57,10 +57,10 @@ describe('to have values satisfying assertion', function () {
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([ [[], { foo: null }] ])
expected new Map[ [[], { foo: null }] ])
to have values satisfying { foo: expect.it('to be a number') }
Map([
new Map[
[[], {
foo: null // should be a number
}]
Expand All @@ -86,7 +86,7 @@ describe('to have values satisfying assertion', function () {
expect.unindent`
expected Map to have values satisfying function myOtherFunction() {}
Map([
new Map[
['foo',
function myFunction() {} // should be function myOtherFunction() {}
]
Expand Down
64 changes: 33 additions & 31 deletions test/assertions/Map.to-satisfy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('to satisfy assertion', function () {
},
'to throw an error satisfying',
'to equal snapshot',
"expected Map([ ['foo', 123] ]) not to satisfy Map([ ['foo', 123] ])"
"expected new Map[ ['foo', 123] ]) not to satisfy new Map[ ['foo', 123] ])"
);
});
});
Expand Down Expand Up @@ -124,9 +124,10 @@ describe('to satisfy assertion', function () {
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([ ['bar', 123] ]) to satisfy Map([ ['foo', undefined], ['bar', 456] ])
expected new Map[ ['bar', 123] ])
to satisfy new Map[ ['foo', undefined], ['bar', 456] ])
Map([
new Map[
['bar',
123 // should equal 456
]
Expand All @@ -150,10 +151,10 @@ describe('to satisfy assertion', function () {
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([ ['foo', 'bar'] ])
to satisfy Map([ ['foo', 'bar'], ['baz', expect.it('to equal', 123)] ])
expected new Map[ ['foo', 'bar'] ])
to satisfy new Map[ ['foo', 'bar'], ['baz', expect.it('to equal', 123)] ])
Map([
new Map[
['foo', 'bar']
// missing: ['baz', should equal 123]
])
Expand Down Expand Up @@ -239,9 +240,9 @@ describe('to satisfy assertion', function () {
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([ ['foo', 'foo'] ]) to satisfy Map([ ['foo', /f00/] ])
expected new Map[ ['foo', 'foo'] ]) to satisfy new Map[ ['foo', /f00/] ])
Map([
new Map[
['foo',
'foo' // should match /f00/
]
Expand All @@ -260,10 +261,10 @@ describe('to satisfy assertion', function () {
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([ ['foo', 'foo'] ])
to satisfy Map([ ['foo', expect.it('not to match', /oo/)] ])
expected new Map[ ['foo', 'foo'] ])
to satisfy new Map[ ['foo', expect.it('not to match', /oo/)] ])
Map([
new Map[
['foo',
'foo' // should not match /oo/
//
Expand Down Expand Up @@ -337,13 +338,13 @@ describe('to satisfy assertion', function () {
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([ ['foo', 123] ]) to satisfy
Map([
expected new Map[ ['foo', 123] ]) to satisfy
new Map[
['foo', expect.it('to be a number')
.and('to be greater than', 200)]
])
Map([
new Map[
['foo',
123 // ✓ should be a number and
// ⨯ should be greater than 200
Expand Down Expand Up @@ -423,10 +424,10 @@ describe('to satisfy assertion', function () {
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([ ['bool', 'true'] ])
to satisfy Map([ ['bool', expect.it('to be true')] ])
expected new Map[ ['bool', 'true'] ])
to satisfy new Map[ ['bool', expect.it('to be true')] ])
Map([
new Map[
['bool',
'true' // expected 'true' to be true
// The assertion does not have a matching signature for:
Expand Down Expand Up @@ -625,9 +626,10 @@ describe('to satisfy assertion', function () {
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([ ['foo', true], ['bar', false] ]) to exhaustively satisfy Map([])
expected new Map[ ['foo', true], ['bar', false] ])
to exhaustively satisfy new Map[])
Map([
new Map[
// should be removed: ['foo', true]
// should be removed: ['bar', false]
])
Expand All @@ -650,9 +652,9 @@ describe('to satisfy assertion', function () {
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([]) to satisfy Map([ ['foo', expect.it('to be a string')] ])
expected new Map[]) to satisfy new Map[ ['foo', expect.it('to be a string')] ])
Map([
new Map[
// missing: ['foo', should be a string]
])
`
Expand Down Expand Up @@ -681,9 +683,9 @@ describe('to satisfy assertion', function () {
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([]) to satisfy Map([ ['foo', expect.it('to be a string')] ])
expected new Map[]) to satisfy new Map[ ['foo', expect.it('to be a string')] ])
Map([
new Map[
// missing: ['foo', should be a string]
])
`
Expand Down Expand Up @@ -719,13 +721,13 @@ describe('to satisfy assertion', function () {
.replace(/function foo/g, 'function '),
'to equal snapshot',
expect.unindent`
expected Map([]) to satisfy
Map([
expected new Map[]) to satisfy
new Map[
['bar', 123],
['foo', expect.it(function (v) { expect(v, 'to be undefined'); })]
])
Map([
new Map[
// missing ['bar', 123]
// missing ['foo', should satisfy expect.it(function (v) { expect(v, 'to be undefined'); })]
])
Expand All @@ -750,10 +752,10 @@ describe('to satisfy assertion', function () {
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([ ['foo', function myFunction() {}] ])
to satisfy Map([ ['foo', function myOtherFunction() {}] ])
expected new Map[ ['foo', function myFunction() {}] ])
to satisfy new Map[ ['foo', function myOtherFunction() {}] ])
Map([
new Map[
['foo',
function myFunction() {} // should be function myOtherFunction() {}
]
Expand All @@ -774,9 +776,9 @@ describe('to satisfy assertion', function () {
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([ ['constructor', 123] ]) to satisfy Map([ ['foo', 456] ])
expected new Map[ ['constructor', 123] ]) to satisfy new Map[ ['foo', 456] ])
Map([
new Map[
['constructor', 123]
// missing ['foo', 456]
])
Expand Down
36 changes: 19 additions & 17 deletions test/types/Map-type.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([ ['quux', 'bar'] ])
to equal Map([ ['quux', 'bar'], ['zuuq', 'baz'] ])
expected new Map[ ['quux', 'bar'] ])
to equal new Map[ ['quux', 'bar'], ['zuuq', 'baz'] ])
Map([
new Map[
['quux', 'bar']
// missing ['zuuq', 'baz']
])
Expand All @@ -49,10 +49,10 @@
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([ ['quux', 'bar'], ['zuuq', 'baz'] ])
to equal Map([ ['quux', 'bar'] ])
expected new Map[ ['quux', 'bar'], ['zuuq', 'baz'] ])
to equal new Map[ ['quux', 'bar'] ])
Map([
new Map[
['quux', 'bar'],
['zuuq', 'baz'] // should be removed
])
Expand All @@ -72,9 +72,9 @@
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([ ['foo', 'bar'] ]) to equal Map([ ['foo', 'baz'] ])
expected new Map[ ['foo', 'bar'] ]) to equal new Map[ ['foo', 'baz'] ])
Map([
new Map[
['foo',
'bar' // should equal 'baz'
//
Expand All @@ -98,9 +98,10 @@
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([ [[ 'a', 'b' ], 'bar'] ]) to equal Map([ [[ 'a', 'c' ], 'bar'] ])
expected new Map[ [[ 'a', 'b' ], 'bar'] ])
to equal new Map[ [[ 'a', 'c' ], 'bar'] ])
Map([
new Map[
[[ 'a', 'b' ], 'bar'] // should be removed
// missing [[ 'a', 'c' ], 'bar']
])
Expand Down Expand Up @@ -137,10 +138,10 @@
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([ [[], { foo: null }] ])
to satisfy Map([ [[], { foo: null }], ['bar', 'baz'] ])
expected new Map[ [[], { foo: null }] ])
to satisfy new Map[ [[], { foo: null }], ['bar', 'baz'] ])
Map([
new Map[
[[], { foo: null }]
// missing ['bar', 'baz']
])
Expand All @@ -160,9 +161,10 @@
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([ ['foo', { foo: null }] ]) to satisfy Map([ ['bar', { foo: null }] ])
expected new Map[ ['foo', { foo: null }] ])
to satisfy new Map[ ['bar', { foo: null }] ])
Map([
new Map[
['foo', { foo: null }]
// missing ['bar', { foo: null }]
])
Expand All @@ -179,7 +181,7 @@
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([]) to equal {}
expected new Map[]) to equal {}
Mismatching constructors Map should be Object
`
Expand All @@ -194,7 +196,7 @@
'to throw an error satisfying',
'to equal snapshot',
expect.unindent`
expected Map([]) to equal {}
expected new Map[]) to equal {}
Mismatching constructors Map should be Object
`
Expand Down

0 comments on commit 18efc34

Please sign in to comment.