Skip to content

Commit 28bbd1b

Browse files
committed
test(@angular-devkit/schematics): test for nested chained function rules
1 parent a7edd57 commit 28bbd1b

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

packages/angular_devkit/schematics/src/engine/schematic_spec.ts

+47
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// tslint:disable:non-null-operator
99
import { logging } from '@angular-devkit/core';
1010
import { of as observableOf } from 'rxjs';
11+
import { chain } from '../rules/base';
1112
import { MergeStrategy, Tree } from '../tree/interface';
1213
import { branch, empty } from '../tree/static';
1314
import { CollectionDescription, Engine, Rule, Schematic, SchematicDescription } from './interface';
@@ -100,4 +101,50 @@ describe('Schematic', () => {
100101
.then(done, done.fail);
101102
});
102103

104+
it('works with nested chained function rules', done => {
105+
let chainCount = 0;
106+
let oneCount = 0;
107+
let twoCount = 0;
108+
let threeCount = 0;
109+
const one = () => {
110+
return chain([
111+
() => { oneCount++; },
112+
]);
113+
};
114+
const two = () => {
115+
return chain([
116+
() => { twoCount++; },
117+
]);
118+
};
119+
const three = () => {
120+
threeCount++;
121+
};
122+
123+
const desc: SchematicDescription<CollectionT, SchematicT> = {
124+
collection,
125+
name: 'test',
126+
description: '',
127+
path: '/a/b/c',
128+
factory: () => {
129+
return chain([
130+
() => { chainCount++; },
131+
one,
132+
two,
133+
three,
134+
]);
135+
},
136+
};
137+
138+
const schematic = new SchematicImpl(desc, desc.factory, null !, engine);
139+
schematic.call({}, observableOf(empty()))
140+
.toPromise()
141+
.then(_x => {
142+
expect(chainCount).toBe(1);
143+
expect(oneCount).toBe(1);
144+
expect(twoCount).toBe(1);
145+
expect(threeCount).toBe(1);
146+
})
147+
.then(done, done.fail);
148+
});
149+
103150
});

0 commit comments

Comments
 (0)