Last active
January 21, 2021 02:19
-
-
Save psenger/1de34e59ea2caa315438e080979a8471 to your computer and use it in GitHub Desktop.
[Jest - How to Parameterized Tests and Describes] #Jest #JavaScript
This file contains hidden or 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
| const not = val => !val; | |
| // How to parameterize describe in jest | |
| describe("index", () => { | |
| describe.each([ | |
| ['boolean', true, false], | |
| ['boolean', false, true], | |
| ['number', 0, true], | |
| ['number', 1, false], | |
| ['number', 999, false], | |
| ['number', -1, false], | |
| ['number', -999, false], | |
| ])('#not', (type, subject, expectedOutcome) => { | |
| test(`When parameter type of '${type}' with value of '${subject}' expected out is '${expectedOutcome}'`, () => { | |
| expect(not(subject)).toEqual(expectedOutcome) | |
| }); | |
| }) | |
| }); |
This file contains hidden or 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
| const not = val => !val; | |
| // How to parameterize tests in jest | |
| describe("index", () => { | |
| describe('#not',() => { | |
| test.each([ | |
| ['boolean', true, false], | |
| ['boolean', false, true], | |
| ['number', 0, true], | |
| ['number', 1, false], | |
| ['number', 999, false], | |
| ['number', -1, false], | |
| ['number', -999, false], | |
| ])(`When parameter type of '%s' with value of '%s' expected out is '%s'`, (type, subject, expectedOutcome) => { | |
| expect(not(subject)).toEqual(expectedOutcome); | |
| }) | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment