forked from jest-community/jest-extended
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
99abdd9
commit 34dfba4
Showing
6 changed files
with
40 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export default (a, b) => b.indexOf(a) > -1; | ||
import { contains } from '../../utils'; | ||
|
||
export default (value, list) => contains(list, value); |
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 |
---|---|---|
@@ -1,11 +1,27 @@ | ||
import each from 'jest-each'; | ||
import predicate from './predicate'; | ||
|
||
describe('.toBeOneOf', () => { | ||
it('passes when value is in given array', () => { | ||
expect(predicate(1, [1, 2, 3])).toBe(true); | ||
each([[1], [null], [undefined], [false], ['']]).it( | ||
'returns true when primitive value: %s is in given array', | ||
value => { | ||
expect(predicate(value, [1, 2, 3, null, undefined, false, ''])).toBe(true); | ||
} | ||
); | ||
|
||
each([[{ hello: 'world' }], [['foo']]]).it('returns true when nested value: %s is in given array', value => { | ||
expect(predicate(value, [1, 2, { hello: 'world' }, ['foo']])).toBe(true); | ||
}); | ||
|
||
it('fails when value is not in given array', () => { | ||
expect(predicate(4, [1, 2, 3])).toBe(false); | ||
each([ | ||
[0], | ||
[null], | ||
[undefined], | ||
[false], | ||
[''], | ||
[{ hello: 'world' }], | ||
[['foo']] | ||
]).it('returns false when value: %s is not in given array', value => { | ||
expect(predicate(value, [1, 2, 3])).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
import { equals } from 'expect/build/jasmine_utils'; | ||
import { contains } from '../../utils'; | ||
|
||
export default (actual, value) => { | ||
const result = Object.keys(actual) | ||
.map(k => actual[k]) | ||
.find(v => equals(v, value)); | ||
|
||
return result !== undefined || value === undefined; | ||
const objectValues = Object.keys(actual).map(k => actual[k]); | ||
return contains(objectValues, value); | ||
}; |
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 |
---|---|---|
@@ -1,10 +1,6 @@ | ||
import { equals } from 'expect/build/jasmine_utils'; | ||
import { contains } from '../../utils'; | ||
|
||
export default (object, values) => { | ||
const objectValues = Object.keys(object).map(k => object[k]); | ||
|
||
return values.every(value => { | ||
const result = objectValues.find(v => equals(v, value)); | ||
return result !== undefined || value === undefined; | ||
}); | ||
return values.every(value => contains(objectValues, value)); | ||
}; |
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