|
| 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