Skip to content

Commit

Permalink
fix(@schematics/angular): test findNodes with recursive flag
Browse files Browse the repository at this point in the history
This change adds unit tests for using `recursive` flag in `findNodes`
  • Loading branch information
jaroslawsawicki authored and clydin committed Oct 6, 2020
1 parent 5db0fb5 commit 8d7703e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions packages/schematics/angular/utility/ast-utils_spec.ts
Expand Up @@ -609,4 +609,45 @@ describe('ast utils', () => {
);
});
});

describe('findNodes', () => {
const filePath = './src/foo.ts';
const fileContent = `
const a = {
nodeAtDepth0: {
nodeAtDepth1: {
nodeAtDepth2: { nodeAtDepth3: 'foo' },
},
},
};
`;

let recursive: boolean;

describe('when `recursive` is not set', () => {
beforeEach(() => {
recursive = false;
});

it('should return node excluding nested nodes', () => {
const source = getTsSource(filePath, fileContent);
const paNodes = findNodes(source, ts.SyntaxKind.PropertyAssignment, Infinity, recursive);

expect(paNodes.length).toEqual(1);
});
});

describe('when `recursive` is set', () => {
beforeEach(() => {
recursive = true;
});

it('should return node including all nested nodes', () => {
const source = getTsSource(filePath, fileContent);
const paNodes = findNodes(source, ts.SyntaxKind.PropertyAssignment, Infinity, recursive);

expect(paNodes.length).toEqual(4);
});
});
});
});

0 comments on commit 8d7703e

Please sign in to comment.