Skip to content

Commit cb45650

Browse files
committed
Remove ViewChild from metadata
ViewChild will always be null, and so there is no point in mocking it. viewChild.required throws an error in mocked components without this change. Fixes GH-8634
1 parent 78b1979 commit cb45650

File tree

3 files changed

+4
-65
lines changed

3 files changed

+4
-65
lines changed

libs/ng-mocks/src/lib/common/decorate.queries.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ const generateFinalQueries = (queries: {
2727

2828
for (const key of Object.keys(queries)) {
2929
const query: Query & { ngMetadataName?: string } = queries[key];
30-
final.push([key, query]);
30+
31+
if (!query.isViewQuery || isInternalKey(key)) {
32+
final.push([key, query]);
33+
}
3134

3235
if (!query.isViewQuery && !isInternalKey(key)) {
3336
scanKeys.push(key);

libs/ng-mocks/src/lib/mock-component/mock-component.spec.ts

-32
Original file line numberDiff line numberDiff line change
@@ -393,22 +393,6 @@ describe('MockComponent', () => {
393393
ngMetadataName: 'ContentChildren',
394394
}),
395395
],
396-
o3: [
397-
jasmine.objectContaining({
398-
selector: 'i3',
399-
isViewQuery: true,
400-
read: TemplateRef,
401-
ngMetadataName: 'ViewChild',
402-
}),
403-
],
404-
o4: [
405-
jasmine.objectContaining({
406-
selector: 'i4',
407-
isViewQuery: true,
408-
read: TemplateRef,
409-
ngMetadataName: 'ViewChildren',
410-
}),
411-
],
412396
o5: [
413397
jasmine.objectContaining({
414398
selector: 'i5',
@@ -425,22 +409,6 @@ describe('MockComponent', () => {
425409
ngMetadataName: 'ContentChildren',
426410
}),
427411
],
428-
o7: [
429-
jasmine.objectContaining({
430-
selector: 'i7',
431-
isViewQuery: true,
432-
read: ElementRef,
433-
ngMetadataName: 'ViewChild',
434-
}),
435-
],
436-
o8: [
437-
jasmine.objectContaining({
438-
selector: 'i8',
439-
isViewQuery: true,
440-
read: ElementRef,
441-
ngMetadataName: 'ViewChildren',
442-
}),
443-
],
444412

445413
__ngMocksVcr_o1: [
446414
jasmine.objectContaining({

libs/ng-mocks/src/lib/mock-directive/mock-directive.spec.ts

-32
Original file line numberDiff line numberDiff line change
@@ -300,22 +300,6 @@ describe('MockDirective', () => {
300300
ngMetadataName: 'ContentChildren',
301301
}),
302302
],
303-
o3: [
304-
jasmine.objectContaining({
305-
selector: 'i3',
306-
isViewQuery: true,
307-
read: TemplateRef,
308-
ngMetadataName: 'ViewChild',
309-
}),
310-
],
311-
o4: [
312-
jasmine.objectContaining({
313-
selector: 'i4',
314-
isViewQuery: true,
315-
read: TemplateRef,
316-
ngMetadataName: 'ViewChildren',
317-
}),
318-
],
319303
o5: [
320304
jasmine.objectContaining({
321305
selector: 'i5',
@@ -332,22 +316,6 @@ describe('MockDirective', () => {
332316
ngMetadataName: 'ContentChildren',
333317
}),
334318
],
335-
o7: [
336-
jasmine.objectContaining({
337-
selector: 'i7',
338-
isViewQuery: true,
339-
read: ElementRef,
340-
ngMetadataName: 'ViewChild',
341-
}),
342-
],
343-
o8: [
344-
jasmine.objectContaining({
345-
selector: 'i8',
346-
isViewQuery: true,
347-
read: ElementRef,
348-
ngMetadataName: 'ViewChildren',
349-
}),
350-
],
351319

352320
__ngMocksVcr_o1: [
353321
jasmine.objectContaining({

0 commit comments

Comments
 (0)