Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
by adding a ponyfill for `Array.prototype.find` to conventions and converting `let` to `var`
- Loading branch information
Showing
3 changed files
with
63 additions
and
15 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
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,24 @@ | ||
'use strict'; | ||
|
||
const { find } = require('../../lib/conventions'); | ||
|
||
describe('find', () => { | ||
it('should work in node without pasing an ArrayConstructor', () => { | ||
const predicate = jest.fn((item) => item === 'b'); | ||
const list = ['a', 'b', 'c']; | ||
|
||
expect(find(list, predicate)).toBe('b'); | ||
expect(predicate).toHaveBeenCalledTimes(2); | ||
expect(predicate).toHaveBeenCalledWith('a', 0, list); | ||
expect(predicate).toHaveBeenCalledWith('b', 1, list); | ||
}); | ||
it('should work when ArrayConstructor does not provide find', () => { | ||
const predicate = jest.fn((item) => item === 'b'); | ||
const list = ['a', 'b', 'c']; | ||
|
||
expect(find(list, predicate, {})).toBe('b'); | ||
expect(predicate).toHaveBeenCalledTimes(2); | ||
expect(predicate).toHaveBeenCalledWith('a', 0, list); | ||
expect(predicate).toHaveBeenCalledWith('b', 1, list); | ||
}); | ||
}); |