Skip to content

Commit 48629f7

Browse files
test: add integration test with ng-mocks (#402)
1 parent 041068c commit 48629f7

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"karma-jasmine": "5.1.0",
9494
"karma-jasmine-html-reporter": "2.0.0",
9595
"lint-staged": "^12.1.6",
96+
"ng-mocks": "^14.11.0",
9697
"ng-packagr": "16.0.0",
9798
"nx": "16.1.4",
9899
"postcss": "^8.4.5",
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { Component, ContentChild, EventEmitter, Input, Output, TemplateRef } from '@angular/core';
2+
import { By } from '@angular/platform-browser';
3+
4+
import { MockComponent } from 'ng-mocks';
5+
import { render } from '../../src/public_api';
6+
7+
test('sends the correct value to the child input', async () => {
8+
const utils = await render(TargetComponent, {
9+
imports: [MockComponent(ChildComponent)],
10+
componentInputs: { value: 'foo' },
11+
});
12+
13+
const children = utils.fixture.debugElement.queryAll(By.directive(ChildComponent));
14+
expect(children).toHaveLength(1);
15+
16+
const mockComponent = children[0].componentInstance;
17+
expect(mockComponent.someInput).toBe('foo');
18+
});
19+
20+
test('sends the correct value to the child input 2', async () => {
21+
const utils = await render(TargetComponent, {
22+
imports: [MockComponent(ChildComponent)],
23+
componentInputs: { value: 'bar' },
24+
});
25+
26+
const children = utils.fixture.debugElement.queryAll(By.directive(ChildComponent));
27+
expect(children).toHaveLength(1);
28+
29+
const mockComponent = children[0].componentInstance;
30+
expect(mockComponent.someInput).toBe('bar');
31+
});
32+
33+
@Component({
34+
selector: 'atl-child',
35+
template: 'child',
36+
standalone: true,
37+
})
38+
class ChildComponent {
39+
@ContentChild('something')
40+
public injectedSomething: TemplateRef<void> | undefined;
41+
42+
@Input()
43+
public someInput = '';
44+
45+
@Output()
46+
public someOutput = new EventEmitter();
47+
48+
public childMockComponent() {
49+
/* noop */
50+
}
51+
}
52+
53+
@Component({
54+
selector: 'atl-target-mock-component',
55+
template: `<atl-child [someInput]="value" (someOutput)="trigger($event)"></atl-child> `,
56+
standalone: true,
57+
imports: [ChildComponent],
58+
})
59+
class TargetComponent {
60+
@Input() value = '';
61+
public trigger = (obj: any) => obj;
62+
}

0 commit comments

Comments
 (0)