Skip to content

Commit

Permalink
[expect] Fix TypeError in toBeInstanceOf on null or undefined (
Browse files Browse the repository at this point in the history
  • Loading branch information
dhoulb authored and SimenB committed Aug 30, 2018
1 parent d235839 commit bfba21c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

### Fixes

- `[expect]` Fix TypeError in `toBeInstanceOf` on `null` or `undefined` ([#6912](https://github.com/facebook/jest/pull/6912))
- `[jest-jasmine2]` Throw a descriptive error if the first argument supplied to a hook was not a function ([#6917](https://github.com/facebook/jest/pull/6917))
- `[jest-circus]` Throw a descriptive error if the first argument supplied to a hook was not a function ([#6917](https://github.com/facebook/jest/pull/6917))
- `[expect]` Fix variadic custom asymmetric matchers ([#6898](https://github.com/facebook/jest/pull/6898))
Expand Down
16 changes: 16 additions & 0 deletions packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,14 @@ Received constructor: <red>Number</>
Received value: <red>1</>"
`;

exports[`.toBeInstanceOf() failing null and [Function String] 1`] = `
"<dim>expect(</><red>value</><dim>).toBeInstanceOf(</><green>constructor</><dim>)</>

Expected constructor: <green>String</>
Received constructor:
Received value: <red>null</>"
`;

exports[`.toBeInstanceOf() failing true and [Function Boolean] 1`] = `
"<dim>expect(</><red>value</><dim>).toBeInstanceOf(</><green>constructor</><dim>)</>

Expand All @@ -1086,6 +1094,14 @@ Received constructor: <red>Boolean</>
Received value: <red>true</>"
`;

exports[`.toBeInstanceOf() failing undefined and [Function String] 1`] = `
"<dim>expect(</><red>value</><dim>).toBeInstanceOf(</><green>constructor</><dim>)</>

Expected constructor: <green>String</>
Received constructor:
Received value: <red>undefined</>"
`;

exports[`.toBeInstanceOf() passing [] and [Function Array] 1`] = `
"<dim>expect(</><red>value</><dim>).</>not<dim>.toBeInstanceOf(</><green>constructor</><dim>)</>

Expand Down
2 changes: 2 additions & 0 deletions packages/expect/src/__tests__/matchers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,8 @@ describe('.toBeInstanceOf()', () => {
[true, Boolean],
[new A(), B],
[Object.create(null), A],
[undefined, String],
[null, String],
].forEach(([a, b]) => {
test(`failing ${stringify(a)} and ${stringify(b)}`, () => {
expect(() =>
Expand Down
4 changes: 3 additions & 1 deletion packages/expect/src/matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ const matchers: MatchersObject = {
constructor.name || String(constructor),
)}\n` +
`Received constructor: ${RECEIVED_COLOR(
received.constructor && received.constructor.name,
received != null
? received.constructor && received.constructor.name
: '',
)}\n` +
`Received value: ${printReceived(received)}`;

Expand Down

0 comments on commit bfba21c

Please sign in to comment.