forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathschema-tree.spec.ts
57 lines (42 loc) · 1.69 KB
/
schema-tree.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
import {readFileSync} from 'fs';
import {join} from 'path';
import {RootSchemaTreeNode} from './schema-tree';
describe('@ngtools/json-schema', () => {
describe('OneOfSchemaTreeNode', () => {
const schemaJsonFilePath = join(__dirname, '../tests/schema1.json');
const schemaJson = JSON.parse(readFileSync(schemaJsonFilePath, 'utf-8'));
const valueJsonFilePath = join(__dirname, '../tests/value1-1.json');
const valueJson = JSON.parse(readFileSync(valueJsonFilePath, 'utf-8'));
it('works', () => {
const proto: any = Object.create(null);
new RootSchemaTreeNode(proto, {
value: valueJson,
schema: schemaJson
});
expect(proto.oneOfKey2 instanceof Array).toBe(true);
expect(proto.oneOfKey2.length).toBe(2);
// Set it to a string, which is valid.
proto.oneOfKey2 = 'hello';
expect(proto.oneOfKey2 instanceof Array).toBe(false);
});
});
describe('EnumSchemaTreeNode', () => {
const schemaJsonFilePath = join(__dirname, '../tests/schema2.json');
const schemaJson = JSON.parse(readFileSync(schemaJsonFilePath, 'utf-8'));
const valueJsonFilePath = join(__dirname, '../tests/value2-1.json');
const valueJson = JSON.parse(readFileSync(valueJsonFilePath, 'utf-8'));
it('works', () => {
const proto: any = Object.create(null);
new RootSchemaTreeNode(proto, {
value: valueJson,
schema: schemaJson
});
expect(proto.a instanceof Array).toBe(true);
expect(proto.a).toEqual([null, 'v1', null, 'v3']);
// Set it to a string, which is valid.
proto.a[0] = 'v2';
proto.a[1] = 'INVALID';
expect(proto.a).toEqual(['v2', null, null, 'v3']);
});
});
});