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

splitWhen.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
27
28
29
30
31
32
33
34
35
import { splitWhen as splitWhenRamda } from 'ramda'
import { equals } from './equals.js'import { splitWhen } from './splitWhen.js'
const list = [ 1, 2, 1, 2 ]
test('happy', () => { const result = splitWhen(equals(2), list) expect(result).toEqual([ [ 1 ], [ 2, 1, 2 ] ])})
test('when predicate returns false', () => { const result = splitWhen(equals(3))(list) expect(result).toEqual([ list, [] ])})
const badInputs = [ 1, true, /foo/g, {} ]const throwingBadInputs = [ null, undefined ]
test('with bad inputs', () => { throwingBadInputs.forEach(badInput => { expect(() => splitWhen(equals(2), badInput)).toThrowWithMessage(TypeError, `Cannot read property 'length' of ${ badInput }`) expect(() => splitWhenRamda(equals(2), badInput)).toThrowWithMessage(TypeError, `Cannot read properties of ${ badInput } (reading 'length')`) })
badInputs.forEach(badInput => { const result = splitWhen(equals(2), badInput) const ramdaResult = splitWhenRamda(equals(2), badInput) expect(result).toEqual(ramdaResult) })})
rambda

Version Info

Tagged at
2 months ago