-
Notifications
You must be signed in to change notification settings - Fork 14
/
immutables.js
69 lines (54 loc) · 1.7 KB
/
immutables.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import * as Immutable from 'immutable'
import test from './test'
import {Record} from '../record'
test('can use Immutable.js objects in records', assert => {
var X = Record({
a: new Immutable.Map({foo: 'bar'}),
})
var x1 = new X()
assert.equals(x1.a.get('foo'), 'bar')
assert.equals(x1.a.get('baz'), undefined)
assert.equals(x1.a.get('baz', 'bacon'), 'bacon')
var x2 = new X({
a: new Immutable.Map({spam: 'eggs'}),
})
assert.equals(x2.a.get('spam'), 'eggs')
assert.equals(x2.a.get('foo'), undefined)
assert.equals(x2.a.get('baz', 'bacon'), 'bacon')
var x3 = new X({
a: {spam: 'eggs'},
})
assert.equals(x3.a instanceof Immutable.Map, true)
assert.equals(x3.a.get('spam'), 'eggs')
assert.equals(x3.a.get('foo'), undefined)
assert.equals(x3.a.get('baz', 'bacon'), 'bacon')
})
test('can use Immutable.js classes in records', assert => {
var X = Record({
a: Immutable.Map,
})
assert.throws(_ => {
var x1 = new X()
})
var x2 = new X({
a: new Immutable.Map({spam: 'eggs'}),
})
assert.equals(x2.a.get('spam'), 'eggs')
assert.equals(x2.a.get('foo'), undefined)
assert.equals(x2.a.get('baz', 'bacon'), 'bacon')
var x3 = new X({
a: {spam: 'eggs'},
})
assert.equals(x3.a instanceof Immutable.Map, true)
assert.equals(x3.a.get('spam'), 'eggs')
assert.equals(x3.a.get('foo'), undefined)
assert.equals(x3.a.get('baz', 'bacon'), 'bacon')
})
test('sets work too', assert => {
var Y = Record({s: new Immutable.Set(['foo'])})
assert.equals(new Y().s.has('foo'), true)
assert.equals(new Y().s.has('bar'), false)
var y2 = new Y({s: ['foo', 'bar', 'baz']})
assert.equals(y2.s.has('baz'), true)
assert.throws(() => { var y3 = new Y({s: null}) })
})