-
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.
## Every Nth item You can quickly take every Nth item from an array ```js it.each(items, N)(...) ``` This is the same as taking the index of the item (zero-based) and doing `k % N === 0` ```js const items = [1, 2, 3, 4, 5, 6, ...] it.each(items, 3)(...) // tests item 1, 4, 7, ... ```
- Loading branch information
Showing
3 changed files
with
43 additions
and
0 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,21 @@ | ||
// @ts-check | ||
/// <reference types="cypress" /> | ||
|
||
import '../../src' | ||
|
||
describe('nth item', () => { | ||
const items = [1, 2, 3, 4] | ||
|
||
context('every 2nd', () => { | ||
// take every 2nd item, same as taking the item's zero-index module 2 | ||
it.each(items, 2)('every 2nd item %K', (x) => { | ||
expect(x, '1 or 3').to.be.oneOf([1, 3]) | ||
}) | ||
}) | ||
|
||
context('every 3nd', () => { | ||
it.each(items, 3)('every 3nd item %K', (x) => { | ||
expect(x, '1 or 4').to.be.oneOf([1, 4]) | ||
}) | ||
}) | ||
}) |
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