Skip to content

Commit 4a0b09a

Browse files
devversionvivian-hu-zz
authored andcommitted
fix(schematics): proper error if name is not specified (#13379)
1 parent 7cd3ef5 commit 4a0b09a

File tree

10 files changed

+55
-25
lines changed

10 files changed

+55
-25
lines changed

src/lib/schematics/address-form/index.spec.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ describe('Material address-form schematic', () => {
4040
expect(moduleContent).toContain('ReactiveFormsModule');
4141
});
4242

43+
it('should throw if no name has been specified', () => {
44+
expect(() => {
45+
runner.runSchematic('address-form', {project: 'material'}, createTestApp(runner));
46+
}).toThrowError(/required property 'name'/);
47+
});
48+
4349
describe('styleext option', () => {
4450
it('should respect the option value', () => {
4551
const tree = runner.runSchematic(
@@ -48,7 +54,7 @@ describe('Material address-form schematic', () => {
4854
expect(tree.files).toContain('/projects/material/src/app/foo/foo.component.scss');
4955
});
5056

51-
it('should fallback to the @schematics/angular:component option value', () => {
57+
it('should fall back to the @schematics/angular:component option value', () => {
5258
const tree = runner.runSchematic(
5359
'address-form', baseOptions, createTestApp(runner, {style: 'less'}));
5460

@@ -64,7 +70,7 @@ describe('Material address-form schematic', () => {
6470
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.css');
6571
});
6672

67-
it('should fallback to the @schematics/angular:component option value', () => {
73+
it('should fall back to the @schematics/angular:component option value', () => {
6874
const tree = runner.runSchematic(
6975
'address-form', baseOptions, createTestApp(runner, {inlineStyle: true}));
7076

@@ -80,7 +86,7 @@ describe('Material address-form schematic', () => {
8086
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.html');
8187
});
8288

83-
it('should fallback to the @schematics/angular:component option value', () => {
89+
it('should fall back to the @schematics/angular:component option value', () => {
8490
const tree = runner.runSchematic(
8591
'address-form', baseOptions, createTestApp(runner, {inlineTemplate: true}));
8692

@@ -96,7 +102,7 @@ describe('Material address-form schematic', () => {
96102
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.spec.ts');
97103
});
98104

99-
it('should fallback to the @schematics/angular:component option value', () => {
105+
it('should fall back to the @schematics/angular:component option value', () => {
100106
const tree = runner.runSchematic(
101107
'address-form', baseOptions, createTestApp(runner, {skipTests: true}));
102108

src/lib/schematics/address-form/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,5 @@
9393
"description": "Specifies if the component is an entry component of declaring module."
9494
}
9595
},
96-
"required": []
96+
"required": ["name"]
9797
}

src/lib/schematics/dashboard/index.spec.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ describe('material-dashboard-schematic', () => {
4444
`import { MatGridListModule, MatCardModule, MatMenuModule, MatIconModule, MatButtonModule } from '@angular/material';`);
4545
});
4646

47+
it('should throw if no name has been specified', () => {
48+
expect(() => {
49+
runner.runSchematic('dashboard', {project: 'material'}, createTestApp(runner));
50+
}).toThrowError(/required property 'name'/);
51+
});
52+
4753
describe('styleext option', () => {
4854
it('should respect the option value', () => {
4955
const tree = runner.runSchematic(
@@ -52,7 +58,7 @@ describe('material-dashboard-schematic', () => {
5258
expect(tree.files).toContain('/projects/material/src/app/foo/foo.component.scss');
5359
});
5460

55-
it('should fallback to the @schematics/angular:component option value', () => {
61+
it('should fall back to the @schematics/angular:component option value', () => {
5662
const tree = runner.runSchematic(
5763
'dashboard', baseOptions, createTestApp(runner, {style: 'less'}));
5864

@@ -68,7 +74,7 @@ describe('material-dashboard-schematic', () => {
6874
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.css');
6975
});
7076

71-
it('should fallback to the @schematics/angular:component option value', () => {
77+
it('should fall back to the @schematics/angular:component option value', () => {
7278
const tree = runner.runSchematic(
7379
'dashboard', baseOptions, createTestApp(runner, {inlineStyle: true}));
7480

@@ -84,7 +90,7 @@ describe('material-dashboard-schematic', () => {
8490
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.html');
8591
});
8692

87-
it('should fallback to the @schematics/angular:component option value', () => {
93+
it('should fall back to the @schematics/angular:component option value', () => {
8894
const tree = runner.runSchematic(
8995
'dashboard', baseOptions, createTestApp(runner, {inlineTemplate: true}));
9096

@@ -100,7 +106,7 @@ describe('material-dashboard-schematic', () => {
100106
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.spec.ts');
101107
});
102108

103-
it('should fallback to the @schematics/angular:component option value', () => {
109+
it('should fall back to the @schematics/angular:component option value', () => {
104110
const tree = runner.runSchematic(
105111
'dashboard', baseOptions, createTestApp(runner, {skipTests: true}));
106112

src/lib/schematics/dashboard/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,5 @@
9393
"description": "Specifies if the component is an entry component of declaring module."
9494
}
9595
},
96-
"required": []
96+
"required": ["name"]
9797
}

src/lib/schematics/nav/index.spec.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ describe('material-nav-schematic', () => {
4646
`MatListModule } from '@angular/material';`);
4747
});
4848

49+
it('should throw if no name has been specified', () => {
50+
expect(() => {
51+
runner.runSchematic('nav', {project: 'material'}, createTestApp(runner));
52+
}).toThrowError(/required property 'name'/);
53+
});
54+
4955
describe('styleext option', () => {
5056
it('should respect the option value', () => {
5157
const tree = runner.runSchematic(
@@ -54,7 +60,7 @@ describe('material-nav-schematic', () => {
5460
expect(tree.files).toContain('/projects/material/src/app/foo/foo.component.scss');
5561
});
5662

57-
it('should fallback to the @schematics/angular:component option value', () => {
63+
it('should fall back to the @schematics/angular:component option value', () => {
5864
const tree = runner.runSchematic(
5965
'nav', baseOptions, createTestApp(runner, {style: 'less'}));
6066

@@ -70,7 +76,7 @@ describe('material-nav-schematic', () => {
7076
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.css');
7177
});
7278

73-
it('should fallback to the @schematics/angular:component option value', () => {
79+
it('should fall back to the @schematics/angular:component option value', () => {
7480
const tree = runner.runSchematic(
7581
'nav', baseOptions, createTestApp(runner, {inlineStyle: true}));
7682

@@ -86,7 +92,7 @@ describe('material-nav-schematic', () => {
8692
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.html');
8793
});
8894

89-
it('should fallback to the @schematics/angular:component option value', () => {
95+
it('should fall back to the @schematics/angular:component option value', () => {
9096
const tree = runner.runSchematic(
9197
'nav', baseOptions, createTestApp(runner, {inlineTemplate: true}));
9298

@@ -102,7 +108,7 @@ describe('material-nav-schematic', () => {
102108
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.spec.ts');
103109
});
104110

105-
it('should fallback to the @schematics/angular:component option value', () => {
111+
it('should fall back to the @schematics/angular:component option value', () => {
106112
const tree = runner.runSchematic(
107113
'nav', baseOptions, createTestApp(runner, {skipTests: true}));
108114

src/lib/schematics/nav/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,5 @@
9393
"description": "Specifies if the component is an entry component of declaring module."
9494
}
9595
},
96-
"required": []
96+
"required": ["name"]
9797
}

src/lib/schematics/table/index.spec.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ describe('material-table-schematic', () => {
5353
`import { MatTableModule, MatPaginatorModule, MatSortModule } from '@angular/material';`);
5454
});
5555

56+
it('should throw if no name has been specified', () => {
57+
expect(() => {
58+
runner.runSchematic('table', {project: 'material'}, createTestApp(runner));
59+
}).toThrowError(/required property 'name'/);
60+
});
61+
5662
describe('styleext option', () => {
5763
it('should respect the option value', () => {
5864
const tree = runner.runSchematic(
@@ -61,7 +67,7 @@ describe('material-table-schematic', () => {
6167
expect(tree.files).toContain('/projects/material/src/app/foo/foo.component.scss');
6268
});
6369

64-
it('should fallback to the @schematics/angular:component option value', () => {
70+
it('should fall back to the @schematics/angular:component option value', () => {
6571
const tree = runner.runSchematic(
6672
'table', baseOptions, createTestApp(runner, {style: 'less'}));
6773

@@ -77,7 +83,7 @@ describe('material-table-schematic', () => {
7783
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.css');
7884
});
7985

80-
it('should fallback to the @schematics/angular:component option value', () => {
86+
it('should fall back to the @schematics/angular:component option value', () => {
8187
const tree = runner.runSchematic(
8288
'table', baseOptions, createTestApp(runner, {inlineStyle: true}));
8389

@@ -93,7 +99,7 @@ describe('material-table-schematic', () => {
9399
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.html');
94100
});
95101

96-
it('should fallback to the @schematics/angular:component option value', () => {
102+
it('should fall back to the @schematics/angular:component option value', () => {
97103
const tree = runner.runSchematic(
98104
'table', baseOptions, createTestApp(runner, {inlineTemplate: true}));
99105

@@ -109,7 +115,7 @@ describe('material-table-schematic', () => {
109115
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.spec.ts');
110116
});
111117

112-
it('should fallback to the @schematics/angular:component option value', () => {
118+
it('should fall back to the @schematics/angular:component option value', () => {
113119
const tree = runner.runSchematic(
114120
'table', baseOptions, createTestApp(runner, {skipTests: true}));
115121

src/lib/schematics/table/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,5 @@
9393
"description": "Specifies if the component is an entry component of declaring module."
9494
}
9595
},
96-
"required": []
96+
"required": ["name"]
9797
}

src/lib/schematics/tree/index.spec.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ describe('Material tree schematic', () => {
3838
expect(moduleContent).toContain('MatButtonModule');
3939
});
4040

41+
it('should throw if no name has been specified', () => {
42+
expect(() => {
43+
runner.runSchematic('tree', {project: 'material'}, createTestApp(runner));
44+
}).toThrowError(/required property 'name'/);
45+
});
46+
4147
describe('styleext option', () => {
4248
it('should respect the option value', () => {
4349
const tree = runner.runSchematic(
@@ -46,7 +52,7 @@ describe('Material tree schematic', () => {
4652
expect(tree.files).toContain('/projects/material/src/app/foo/foo.component.scss');
4753
});
4854

49-
it('should fallback to the @schematics/angular:component option value', () => {
55+
it('should fall back to the @schematics/angular:component option value', () => {
5056
const tree = runner.runSchematic(
5157
'tree', baseOptions, createTestApp(runner, {style: 'less'}));
5258

@@ -62,7 +68,7 @@ describe('Material tree schematic', () => {
6268
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.css');
6369
});
6470

65-
it('should fallback to the @schematics/angular:component option value', () => {
71+
it('should fall back to the @schematics/angular:component option value', () => {
6672
const tree = runner.runSchematic(
6773
'tree', baseOptions, createTestApp(runner, {inlineStyle: true}));
6874

@@ -78,7 +84,7 @@ describe('Material tree schematic', () => {
7884
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.html');
7985
});
8086

81-
it('should fallback to the @schematics/angular:component option value', () => {
87+
it('should fall back to the @schematics/angular:component option value', () => {
8288
const tree = runner.runSchematic(
8389
'tree', baseOptions, createTestApp(runner, {inlineTemplate: true}));
8490

@@ -94,7 +100,7 @@ describe('Material tree schematic', () => {
94100
expect(tree.files).not.toContain('/projects/material/src/app/foo/foo.component.spec.ts');
95101
});
96102

97-
it('should fallback to the @schematics/angular:component option value', () => {
103+
it('should fall back to the @schematics/angular:component option value', () => {
98104
const tree = runner.runSchematic(
99105
'tree', baseOptions, createTestApp(runner, {skipTests: true}));
100106

src/lib/schematics/tree/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,5 @@
9393
"description": "Specifies if the component is an entry component of declaring module."
9494
}
9595
},
96-
"required": []
96+
"required": ["name"]
9797
}

0 commit comments

Comments
 (0)