How can I use @Output communication in my test integration?
See original GitHub issueHi,
How can I use @Ouput communincation between my child and parent component?
header-back-button.component.ts (parente component)
@Component({
selector: 'cebs-header-back-button',
template: `
<header>
<cebs-icon-button
icon="chevron_left"
aria-label="back button"
(clickEvent)="goBack()"
></cebs-icon-button>
</header>
`,
styles: [
`
:host {
width: 100%;
}
header {
display: flex;
}
`,
],
})
export class HeaderBackButtonComponent {
constructor(private location: Location) {}
goBack(): void {
this.location.back()
}
}
icon-button.component.ts (child component)
@Component({
selector: 'cebs-icon-button',
template: `
<button (click)="onClick()" aria-label="icon button">
<span class="material-symbols-outlined icon">{{ icon }}</span>
</button>
`,
styles: [
`
button {
border: none;
width: 40px;
height: 40px;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
background-color: var(--primary-color);
}
.icon {
color: white;
}
`,
],
})
export class IconButtonComponent {
@Output() clickEvent = new EventEmitter()
@Input() icon!: string
onClick(): void {
this.clickEvent.emit()
}
}
header-back-button.component.spec.ts (my test)
describe('HeaderBackButtonComponent', () => {
it('should render a header back button component', async () => {
await render(HeaderBackButtonComponent, {
declarations: [IconButtonComponent],
})
expect(screen.getByLabelText(/back button/i)).toBeDefined()
expect(screen.getByLabelText(/icon button/i)).toBeDefined()
})
it('should call a Location.back when user click in the button', async () => {
const goBackSpy = jest.fn()
await render(HeaderBackButtonComponent, {
declarations: [IconButtonComponent],
componentProperties: {
goBack: goBackSpy,
},
})
const location = TestBed.inject(Location)
jest.spyOn(location, 'back')
const button = screen.getByLabelText(/icon button/i)
userEvent.click(button)
expect(goBackSpy).toHaveBeenCalled()
})
})
when I try to test my expect toHaveBeenCalled is not work, because the output in the child component is not emit
Issue Analytics
- State:
- Created a year ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
What is Integration Testing (Tutorial ... - Software Testing Help
Integration testing is done to test the modules/components when integrated to verify that they work as expected i.e. to test the modules which ......
Read more >Integration Testing: What is, Types with Example - Guru99
1, Check the interface link between the Login and Mailbox module, Enter login credentials and click on the Login button ; 2, Check...
Read more >Integration Tests on Node.js CLI: Part 3 – Inter Process ...
So I started looking into ways to communicate with the parent process (the test runner) for it to send down information to the...
Read more >Integration Testing and its power while testing Microservices ...
In this video, we will discuss how we can perform Integration testing of Microservices to make more realistic testing and run tests in ......
Read more >What is Integration Testing? | Edureka - YouTube
Test Automation Masters Program: https://www.edureka.co/masters-program/automation- testing -engineer-training **)This Edureka video on "What ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Glad we were able to resovle this. Have a great weekend @jadir-junior !
Thank you very much @timdeschryver, You save my life 😆