Repository navigation
Expand file tree
/
Copy pathcall_spec.ts
More file actions
163 lines (141 loc) · 4.01 KB
/
Copy pathcall_spec.ts
File metadata and controls
163 lines (141 loc) · 4.01 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { MergeStrategy } from '@angular-devkit/schematics';
import { of as observableOf } from 'rxjs';
import { Rule, SchematicContext, Source } from '../engine/interface';
import { Tree } from '../tree/interface';
import { empty } from '../tree/static';
import {
InvalidRuleResultException,
InvalidSourceResultException,
callRule,
callSource,
} from './call';
const context: SchematicContext = ({
engine: null,
debug: false,
strategy: MergeStrategy.Default,
} as {}) as SchematicContext;
describe('callSource', () => {
it('errors if undefined source', (done) => {
const source0: any = () => undefined;
callSource(source0, context)
.toPromise()
.then(
() => done.fail(),
(err) => {
expect(err).toEqual(new InvalidSourceResultException());
},
)
.then(done, done.fail);
});
it('errors if invalid source object', (done) => {
const source0: Source = () => ({} as Tree);
callSource(source0, context)
.toPromise()
.then(
() => done.fail(),
(err) => {
expect(err).toEqual(new InvalidSourceResultException({}));
},
)
.then(done, done.fail);
});
it('errors if Observable of invalid source object', (done) => {
const source0: Source = () => observableOf({} as Tree);
callSource(source0, context)
.toPromise()
.then(
() => done.fail(),
(err) => {
expect(err).toEqual(new InvalidSourceResultException({}));
},
)
.then(done, done.fail);
});
it('works with a Tree', (done) => {
const tree0 = empty();
const source0: Source = () => tree0;
callSource(source0, context)
.toPromise()
.then((tree) => {
expect(tree).toBe(tree0);
})
.then(done, done.fail);
});
it('works with an Observable', (done) => {
const tree0 = empty();
const source0: Source = () => observableOf(tree0);
callSource(source0, context)
.toPromise()
.then((tree) => {
expect(tree).toBe(tree0);
})
.then(done, done.fail);
});
});
describe('callRule', () => {
it('errors if invalid source object', (done) => {
const tree0 = observableOf(empty());
const rule0: Rule = () => ({} as Tree);
callRule(rule0, tree0, context)
.toPromise()
.then(
() => done.fail(),
(err) => {
expect(err).toEqual(new InvalidRuleResultException({}));
},
)
.then(done, done.fail);
});
it('errors if Observable of invalid source object', (done) => {
const tree0 = observableOf(empty());
const rule0: Rule = () => observableOf({} as Tree);
callRule(rule0, tree0, context)
.toPromise()
.then(
() => done.fail(),
(err) => {
expect(err).toEqual(new InvalidRuleResultException({}));
},
)
.then(done, done.fail);
});
it('works with undefined result', (done) => {
const tree0 = empty();
const rule0: Rule = () => undefined;
callRule(rule0, observableOf(tree0), context)
.toPromise()
.then((tree) => {
expect(tree).toBe(tree0);
})
.then(done, done.fail);
});
it('works with a Tree', (done) => {
const tree0 = empty();
const rule0: Rule = () => tree0;
callRule(rule0, observableOf(tree0), context)
.toPromise()
.then((tree) => {
expect(tree).toBe(tree0);
})
.then(done, done.fail);
});
it('works with an Observable', (done) => {
const tree0 = empty();
const rule0: Rule = () => observableOf(tree0);
callRule(rule0, observableOf(tree0), context)
.toPromise()
.then((tree) => {
expect(tree).toBe(tree0);
})
.then(done, done.fail);
});
});