deno.land / x / rambda@v9.1.1 / source / pathSatisfies.spec.js

pathSatisfies.spec.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { pathSatisfies } from './pathSatisfies';
const isPositive = (n) => n > 0;
it('returns true if the specified object path satisfies the given predicate', () => { expect( pathSatisfies(isPositive, ['x', 1, 'y'], { x: [{ y: -1 }, { y: 1 }] }), ).toBe(true); expect( pathSatisfies(isPositive, 'x.1.y', { x: [{ y: -1 }, { y: 1 }] }), ).toBe(true);});
it('returns false if the specified path does not exist', () => { expect(pathSatisfies(isPositive, ['x', 'y'], { x: { z: 42 } })).toBe(false); expect(pathSatisfies(isPositive, 'x.y', { x: { z: 42 } })).toBe(false);});
it('throws on empty paths', () => { expect(() => pathSatisfies(Object.is, [], { x: { z: 42 } })).toThrow();});
it('returns false otherwise', () => { expect(pathSatisfies(isPositive, ['x', 'y'], { x: { y: 0 } })).toBe(false);});
rambda

Version Info

Tagged at
2 months ago