forked from immutable-js/immutable-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Record.ts
54 lines (41 loc) · 1.3 KB
/
Record.ts
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
///<reference path='../resources/jest.d.ts'/>
jest.autoMockOff();
import Immutable = require('../dist/Immutable');
import Record = Immutable.Record;
describe('Record', () => {
it('defines a constructor', () => {
var MyType = Record({a:1, b:2, c:3});
var t1 = new MyType();
var t2 = t1.set('a', 10);
var t3 = t2.clear();
expect(t1 instanceof Record);
expect(t1 instanceof MyType);
expect(t3 instanceof Record);
expect(t3 instanceof MyType);
expect(t1.get('a')).toBe(1);
expect(t2.get('a')).toBe(10);
expect(t1.length).toBe(3);
expect(t2.length).toBe(3);
})
it('only persists values it knows about', () => {
var MyType = Record({a:1, b:2, c:3});
var t1 = new MyType({a: 10, b:20});
var t2 = t1.set('d', 4);
var t3 = t2.delete('a');
var t4 = t3.clear();
expect(t1.length).toBe(3);
expect(t2.length).toBe(3);
expect(t3.length).toBe(3);
expect(t4.length).toBe(3);
expect(t1.get('a')).toBe(10);
expect(t2.get('d')).toBe(undefined);
expect(t3.get('a')).toBe(1);
expect(t4.get('b')).toBe(2);
})
it('converts sequences to records', () => {
var MyType = Record({a:1, b:2, c:3});
var seq = Immutable.Sequence({a: 10, b:20});
var t = new MyType(seq);
expect(t.toObject()).toEqual({a:10, b:20, c:3})
})
});