Skip to content
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

feat: add toast details in platformShowToastEvent stub #331

Merged
merged 2 commits into from
Aug 8, 2023
Merged

feat: add toast details in platformShowToastEvent stub #331

merged 2 commits into from
Aug 8, 2023

Conversation

pozil
Copy link
Contributor

@pozil pozil commented Aug 4, 2023

When testing a component that fires multiple toast with platformShowToastEvent we need to access the toast configuration in tests like this (full source):

// Mock handler for toast event
const handler = jest.fn();
// Add event listener to catch toast event
element.addEventListener(ShowToastEventName, handler);

// Some test logic

// Testing fired event
expect(handler).toHaveBeenCalled();
expect(handler.mock.calls[0][0].detail.title).toBe(TOAST_TITLE);
expect(handler.mock.calls[0][0].detail.message).toBe(TOAST_MESSAGE);
expect(handler.mock.calls[0][0].detail.variant).toBe(TOAST_VARIANT);

The previous version of the stub did not allow to pass the toast configuration so I made a PR to enable it.

For reference, we've been using this updated stub in our LWC Recipes tests for years.

@Templarian Templarian self-assigned this Aug 8, 2023
@Templarian Templarian merged commit 6e4190c into salesforce:master Aug 8, 2023
1 check passed
@pozil pozil deleted the pozil/toast-stub-details branch August 9, 2023 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants