deno.land / x / rambda@v9.1.1 / source / is.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
36
37
38
39
40
41
42
43
44
45
46
import { is } from './is.js'
test('works with built-in types', () => { expect(is(Array, undefined)).toBeFalse() expect(is(Array)([])).toBeTrue() expect(is(Boolean, new Boolean(false))).toBeTrue() expect(is(Date, new Date())).toBeTrue() expect(is(Function, () => {})).toBeTrue() expect(is(Number, new Number(0))).toBeTrue() expect(is(Object, {})).toBeTrue() expect(is(RegExp, /(?:)/)).toBeTrue() expect(is(String, new String(''))).toBeTrue()})
test('works with user-defined types', () => { function Foo(){} function Bar(){} Bar.prototype = new Foo()
const foo = new Foo() const bar = new Bar()
expect(is(Foo, foo)).toBeTrue() expect(is(Bar, bar)).toBeTrue() expect(is(Foo, bar)).toBeTrue() expect(is(Bar, foo)).toBeFalse()})
test('does not coerce', () => { expect(is(Boolean, 1)).toBeFalse() expect(is(Number, '1')).toBeFalse() expect(is(Number, false)).toBeFalse()})
test('recognizes primitives as their object equivalents', () => { expect(is(Boolean, false)).toBeTrue() expect(is(Number, 0)).toBeTrue() expect(is(String, '')).toBeTrue()})
test('does not consider primitives to be instances of Object', () => { expect(is(Object, false)).toBeFalse() expect(is(Object, 0)).toBeFalse() expect(is(Object, '')).toBeFalse()})
rambda

Version Info

Tagged at
2 months ago