-
-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trigger custom component event #249
Comments
Invoke the method: it('should emit the $event on click', () => {
let output;
spectator.output('click').subscribe(result => (output = result));
spectator.component.onClick({ type: 'click' });
expect(output).toEqual({ type: 'click' });
}); |
Are you asking about custom elements with custom events or Angular components with output properties? What are you trying to dispatch and trigger? |
Sorry, forgot to answer this.... I'm talking about exactly what's described in the article. Let say we have :
And the working test :
Or alternatively :
In both case we need to call It would be more straightforward to be able to do something like this :
Basically https:/ngneat/spectator#events-api but for custom event |
I thought you meant CustomEvents from a web component. Your example is the output property of a view child Angular component emitting a component-specific event. |
Read Mocking Components in the documentation. |
@Wykks do you want to create a PR? |
@LayZeeDK I'm not sure I understand what you're talking about... I can try do to a PR, yes :) |
I'm submitting a...
I saw this nice article about simulating events in angular tests: https://netbasal.com/simulating-events-in-angular-unit-tests-5482618cd6c6
It's also talking about spectator at the end, but I actually don't find any info about how to trigger custom component event using spectator.
Are you supposed to do
spectator.debugElement.triggerEventHandler('customOutput', {customData})
, followed by adetectChanges
?That's seems a little bit off, since spectator provide helpers for native events. (There's
spectator.dispatchFakeEvent
, but it doesn't take custom data).Am I missing something ?
Environment
The text was updated successfully, but these errors were encountered: