|
| 1 | +/** |
| 2 | + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + */ |
| 8 | + |
| 9 | +import fc from 'fast-check'; |
| 10 | +import { |
| 11 | + anythingSettings, |
| 12 | + assertSettings, |
| 13 | +} from './__arbitraries__/sharedSettings'; |
| 14 | + |
| 15 | +describe('toContain', () => { |
| 16 | + it('should always find the value when inside the array', () => { |
| 17 | + fc.assert( |
| 18 | + fc.property( |
| 19 | + fc.array(fc.anything(anythingSettings)), |
| 20 | + fc.array(fc.anything(anythingSettings)), |
| 21 | + fc.anything(anythingSettings).filter(v => !Number.isNaN(v)), |
| 22 | + (startValues, endValues, v) => { |
| 23 | + // Given: startValues, endValues arrays and v value (not NaN) |
| 24 | + // Assert: We expect `expect([...startValues, v, ...endValues]).toContain(v)` |
| 25 | + expect([...startValues, v, ...endValues]).toContain(v); |
| 26 | + }, |
| 27 | + ), |
| 28 | + assertSettings, |
| 29 | + ); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should not find the value if it has been cloned into the array', () => { |
| 33 | + fc.assert( |
| 34 | + fc.property( |
| 35 | + fc.array(fc.anything(anythingSettings)), |
| 36 | + fc.array(fc.anything(anythingSettings)), |
| 37 | + fc.dedup(fc.anything(anythingSettings), 2), |
| 38 | + (startValues, endValues, [a, b]) => { |
| 39 | + // Given: startValues, endValues arrays |
| 40 | + // and [a, b] equal, but not the same values |
| 41 | + // with `typeof a === 'object && a !== null` |
| 42 | + // Assert: We expect `expect([...startValues, a, ...endValues]).not.toContain(b)` |
| 43 | + fc.pre(typeof a === 'object' && a !== null); |
| 44 | + expect([...startValues, a, ...endValues]).not.toContain(b); |
| 45 | + }, |
| 46 | + ), |
| 47 | + assertSettings, |
| 48 | + ); |
| 49 | + }); |
| 50 | +}); |
0 commit comments