-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add failing test for the test object * add test case object support * update docs * more linting
- Loading branch information
Showing
5 changed files
with
132 additions
and
23 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import '../../src' | ||
|
||
function add(a: number, b: number) { | ||
return a + b | ||
} | ||
|
||
const testCases = { | ||
// key: the test label | ||
// value: list of inputs for each test case | ||
'positive numbers': [1, 6, 7], // [a, b, expected result] | ||
'negative numbers': [1, -6, -5], | ||
} | ||
|
||
describe('converted to an array of arrays', () => { | ||
// we can convert the above object ourselves | ||
const pairs = Cypress._.toPairs(testCases) | ||
it.each(pairs)('testing %0', (title, numbers) => { | ||
const [a, b, expectedResult] = numbers | ||
expect(add(a, b)).to.equal(expectedResult) | ||
}) | ||
}) | ||
|
||
// https://github.com/bahmutov/cypress-each/issues/53 | ||
describe('automatic conversion', () => { | ||
it.each(testCases)((a: number, b: number, expectedResult: number) => { | ||
expect(add(a, b)).to.equal(expectedResult) | ||
}) | ||
|
||
context('plain values', () => { | ||
const evenCases = { | ||
two: 2, | ||
four: 4, | ||
} | ||
|
||
function isEven(x: number) { | ||
return x % 2 === 0 | ||
} | ||
|
||
it.each(evenCases)((x) => { | ||
expect(x).to.satisfy(isEven) | ||
}) | ||
}) | ||
}) |
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