Skip to content

Commit 8d7703e

Browse files
jaroslawsawickiclydin
authored andcommitted
fix(@schematics/angular): test findNodes with recursive flag
This change adds unit tests for using `recursive` flag in `findNodes`
1 parent 5db0fb5 commit 8d7703e

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

packages/schematics/angular/utility/ast-utils_spec.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,4 +609,45 @@ describe('ast utils', () => {
609609
);
610610
});
611611
});
612+
613+
describe('findNodes', () => {
614+
const filePath = './src/foo.ts';
615+
const fileContent = `
616+
const a = {
617+
nodeAtDepth0: {
618+
nodeAtDepth1: {
619+
nodeAtDepth2: { nodeAtDepth3: 'foo' },
620+
},
621+
},
622+
};
623+
`;
624+
625+
let recursive: boolean;
626+
627+
describe('when `recursive` is not set', () => {
628+
beforeEach(() => {
629+
recursive = false;
630+
});
631+
632+
it('should return node excluding nested nodes', () => {
633+
const source = getTsSource(filePath, fileContent);
634+
const paNodes = findNodes(source, ts.SyntaxKind.PropertyAssignment, Infinity, recursive);
635+
636+
expect(paNodes.length).toEqual(1);
637+
});
638+
});
639+
640+
describe('when `recursive` is set', () => {
641+
beforeEach(() => {
642+
recursive = true;
643+
});
644+
645+
it('should return node including all nested nodes', () => {
646+
const source = getTsSource(filePath, fileContent);
647+
const paNodes = findNodes(source, ts.SyntaxKind.PropertyAssignment, Infinity, recursive);
648+
649+
expect(paNodes.length).toEqual(4);
650+
});
651+
});
652+
});
612653
});

0 commit comments

Comments
 (0)