-
-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
overlookmotel
authored
Oct 11, 2021
1 parent
c4961cd
commit adb82b8
Showing
8 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`.not.toBeSymbol fails when given a symbol 1`] = ` | ||
"<dim>expect(</><red>received</><dim>).not.toBeSymbol()</> | ||
Expected value to not be a symbol, received: | ||
<red>Symbol()</>" | ||
`; | ||
exports[`.toBeSymbol fails when not given a symbol 1`] = ` | ||
"<dim>expect(</><red>received</><dim>).toBeSymbol()</> | ||
Expected to receive a symbol, received: | ||
<red>false</>" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { matcherHint, printReceived } from 'jest-matcher-utils'; | ||
|
||
import predicate from './predicate'; | ||
|
||
const passMessage = received => () => | ||
matcherHint('.not.toBeSymbol', 'received', '') + | ||
'\n\n' + | ||
'Expected value to not be a symbol, received:\n' + | ||
` ${printReceived(received)}`; | ||
|
||
const failMessage = received => () => | ||
matcherHint('.toBeSymbol', 'received', '') + | ||
'\n\n' + | ||
'Expected to receive a symbol, received:\n' + | ||
` ${printReceived(received)}`; | ||
|
||
export default { | ||
toBeSymbol: expected => { | ||
const pass = predicate(expected); | ||
if (pass) { | ||
return { pass: true, message: passMessage(expected) }; | ||
} | ||
|
||
return { pass: false, message: failMessage(expected) }; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import matcher from './'; | ||
|
||
expect.extend(matcher); | ||
|
||
describe('.toBeSymbol', () => { | ||
test('passes when given a symbol', () => { | ||
expect(Symbol()).toBeSymbol(); | ||
}); | ||
|
||
test('fails when not given a symbol', () => { | ||
expect(() => expect(false).toBeSymbol()).toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('.not.toBeSymbol', () => { | ||
test.each([[false], [''], [0], [{}], [[]], [undefined], [null], [NaN], [() => {}]])( | ||
'passes when not given a symbol: %s', | ||
given => { | ||
expect(given).not.toBeSymbol(); | ||
}, | ||
); | ||
|
||
test('fails when given a symbol', () => { | ||
expect(() => expect(Symbol()).not.toBeSymbol()).toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default expected => typeof expected === 'symbol'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import predicate from './predicate'; | ||
|
||
describe('toBeSymbol Predicate', () => { | ||
test('returns true when given a symbol', () => { | ||
expect(predicate(Symbol())).toBe(true); | ||
}); | ||
|
||
test.each([[false], [''], [0], [{}], [[]], [undefined], [null], [NaN], [() => {}]])( | ||
'returns false when given: %s', | ||
given => { | ||
expect(predicate(given)).toBe(false); | ||
}, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters