Skip to content

Commit 7f3fae9

Browse files
committed
fix(@schematics/angular): implements items type
Fixes the type of the items in the `schema.json` for `implements`, as `enum` is not picked up by the CLI. Also migrates the existing e2e test to `async/await` and adds another one with `implements` to avoid regressions.
1 parent ab8d197 commit 7f3fae9

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

packages/schematics/angular/guard/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
import { applyLintFix } from '../utility/lint-fix';
2323
import { parseName } from '../utility/parse-name';
2424
import { createDefaultPath } from '../utility/workspace';
25-
import { Implement as GuardInterface, Schema as GuardOptions } from './schema';
25+
import { Schema as GuardOptions } from './schema';
2626

2727

2828
export default function (options: GuardOptions): Rule {
@@ -38,7 +38,7 @@ export default function (options: GuardOptions): Rule {
3838
const implementations = options.implements.join(', ');
3939
let implementationImports = `${implementations}, `;
4040
// As long as we aren't in IE... ;)
41-
if (options.implements.includes(GuardInterface.CanLoad)) {
41+
if (options.implements.includes('CanLoad')) {
4242
implementationImports = `${implementationImports}Route, UrlSegment, `;
4343
}
4444

packages/schematics/angular/guard/schema.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@
5555
"description": "Specifies which interfaces to implement.",
5656
"uniqueItems": true,
5757
"items": {
58-
"enum": [
59-
"CanActivate",
60-
"CanActivateChild",
61-
"CanLoad"
62-
]
58+
"type": "string"
6359
},
6460
"default": [
6561
"CanActivate"
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import {join} from 'path';
22
import {ng} from '../../../utils/process';
3-
import {expectFileToExist} from '../../../utils/fs';
3+
import {expectFileToExist, expectFileToMatch} from '../../../utils/fs';
44

55

6-
export default function() {
6+
export default async function() {
77
// Does not create a sub directory.
88
const guardDir = join('src', 'app');
99

10-
return ng('generate', 'guard', 'test-guard')
11-
.then(() => expectFileToExist(guardDir))
12-
.then(() => expectFileToExist(join(guardDir, 'test-guard.guard.ts')))
13-
.then(() => expectFileToExist(join(guardDir, 'test-guard.guard.spec.ts')));
14-
15-
16-
// Try to run the unit tests.
17-
// TODO: Enable once schematic is updated for rxjs 6
18-
// .then(() => ng('test', '--watch=false'));
10+
await ng('generate', 'guard', 'test-guard');
11+
await expectFileToExist(guardDir);
12+
await expectFileToExist(join(guardDir, 'test-guard.guard.ts'));
13+
await expectFileToMatch(join(guardDir, 'test-guard.guard.ts'), /implements CanActivate/);
14+
await expectFileToExist(join(guardDir, 'test-guard.guard.spec.ts'));
15+
await ng('test', '--watch=false');
1916
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {join} from 'path';
2+
import {ng} from '../../../utils/process';
3+
import {expectFileToExist,expectFileToMatch} from '../../../utils/fs';
4+
5+
6+
export default async function() {
7+
// Does not create a sub directory.
8+
const guardDir = join('src', 'app');
9+
10+
await ng('generate', 'guard', 'load', '--implements=CanLoad');
11+
await expectFileToExist(guardDir);
12+
await expectFileToExist(join(guardDir, 'load.guard.ts'));
13+
await expectFileToMatch(join(guardDir, 'load.guard.ts'), /implements CanLoad/);
14+
await expectFileToExist(join(guardDir, 'load.guard.spec.ts'));
15+
await ng('test', '--watch=false');
16+
}

0 commit comments

Comments
 (0)