Skip to content

Commit

Permalink
fix(root): Remove ViewChild from metadata
Browse files Browse the repository at this point in the history
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 help-me-momGH-8634
  • Loading branch information
c-harding committed Apr 16, 2024
1 parent 78b1979 commit 4421a1c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 65 deletions.
5 changes: 4 additions & 1 deletion libs/ng-mocks/src/lib/common/decorate.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ const generateFinalQueries = (queries: {

for (const key of Object.keys(queries)) {
const query: Query & { ngMetadataName?: string } = queries[key];
final.push([key, query]);

if (!query.isViewQuery || isInternalKey(key)) {
final.push([key, query]);
}

if (!query.isViewQuery && !isInternalKey(key)) {
scanKeys.push(key);
Expand Down
32 changes: 0 additions & 32 deletions libs/ng-mocks/src/lib/mock-component/mock-component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,22 +393,6 @@ describe('MockComponent', () => {
ngMetadataName: 'ContentChildren',
}),
],
o3: [
jasmine.objectContaining({
selector: 'i3',
isViewQuery: true,
read: TemplateRef,
ngMetadataName: 'ViewChild',
}),
],
o4: [
jasmine.objectContaining({
selector: 'i4',
isViewQuery: true,
read: TemplateRef,
ngMetadataName: 'ViewChildren',
}),
],
o5: [
jasmine.objectContaining({
selector: 'i5',
Expand All @@ -425,22 +409,6 @@ describe('MockComponent', () => {
ngMetadataName: 'ContentChildren',
}),
],
o7: [
jasmine.objectContaining({
selector: 'i7',
isViewQuery: true,
read: ElementRef,
ngMetadataName: 'ViewChild',
}),
],
o8: [
jasmine.objectContaining({
selector: 'i8',
isViewQuery: true,
read: ElementRef,
ngMetadataName: 'ViewChildren',
}),
],

__ngMocksVcr_o1: [
jasmine.objectContaining({
Expand Down
32 changes: 0 additions & 32 deletions libs/ng-mocks/src/lib/mock-directive/mock-directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,22 +300,6 @@ describe('MockDirective', () => {
ngMetadataName: 'ContentChildren',
}),
],
o3: [
jasmine.objectContaining({
selector: 'i3',
isViewQuery: true,
read: TemplateRef,
ngMetadataName: 'ViewChild',
}),
],
o4: [
jasmine.objectContaining({
selector: 'i4',
isViewQuery: true,
read: TemplateRef,
ngMetadataName: 'ViewChildren',
}),
],
o5: [
jasmine.objectContaining({
selector: 'i5',
Expand All @@ -332,22 +316,6 @@ describe('MockDirective', () => {
ngMetadataName: 'ContentChildren',
}),
],
o7: [
jasmine.objectContaining({
selector: 'i7',
isViewQuery: true,
read: ElementRef,
ngMetadataName: 'ViewChild',
}),
],
o8: [
jasmine.objectContaining({
selector: 'i8',
isViewQuery: true,
read: ElementRef,
ngMetadataName: 'ViewChildren',
}),
],

__ngMocksVcr_o1: [
jasmine.objectContaining({
Expand Down

0 comments on commit 4421a1c

Please sign in to comment.