forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
observablejson.spec.ts
84 lines (61 loc) · 1.92 KB
/
observablejson.spec.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import expect = require('expect.js');
import {
IObservableJSON, ObservableJSON
} from '@jupyterlab/coreutils';
describe('@jupyterlab/coreutils', () => {
describe('ObservableJSON', () => {
describe('#constructor()', () => {
it('should create an observable JSON object', () => {
let item = new ObservableJSON();
expect(item).to.be.an(ObservableJSON);
});
it('should accept initial values', () => {
let item = new ObservableJSON({
values: { 'foo': 1, 'bar': 'baz'}
});
expect(item).to.be.an(ObservableJSON);
});
});
describe('#toJSON()', () => {
it('should serialize the model to JSON', () => {
let item = new ObservableJSON();
item.set('foo', 1);
expect(item.toJSON()['foo']).to.be(1);
});
it('should return a copy of the data', () => {
let item = new ObservableJSON();
item.set('foo', { 'bar': 1 });
let value = item.toJSON();
value['bar'] = 2;
expect((item.get('foo') as any)['bar']).to.be(1);
});
});
});
describe('ObservableJSON.ChangeMessage', () => {
describe('#constructor()', () => {
it('should create a new message', () => {
let message = new ObservableJSON.ChangeMessage({
key: 'foo',
type: 'add',
oldValue: 1,
newValue: 2
});
expect(message).to.be.a(ObservableJSON.ChangeMessage);
});
});
describe('#args', () => {
it('should be the args of the message', () => {
let args: IObservableJSON.IChangedArgs = {
key: 'foo',
type: 'add',
oldValue: 'ho',
newValue: 'hi'
};
let message = new ObservableJSON.ChangeMessage(args);
expect(message.args).to.be(args);
});
});
});
});