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

Cannot Find lightning/toast Module #352

Open
freddysilber opened this issue Mar 19, 2024 · 2 comments
Open

Cannot Find lightning/toast Module #352

freddysilber opened this issue Mar 19, 2024 · 2 comments

Comments

@freddysilber
Copy link

Description

When running unit tests using the new `lightning/toast' module, I get an error.

Cannot find module 'lightning/toast' from 'path/to/lightningComponent/js'

Steps to Reproduce

// JS for component under test
import { LightningElement } from 'lwc';
import Toast from 'lightning/toast';

export default class Foo extends LightningElement {
  showToast() {
    Toast.show(
      {
        label: 'Error!',
        message: 'There was an error getting data!',
        mode: 'sticky',
        variant: 'error',
      },
      this
    );
  }
}
# Command to repro
sfdx-lwc-jest -- --no-cache

Expected Results

Test to pass

Actual Results

Cannot find module 'lightning/toast' from 'path/to/lightningComponent/js'

Version

  • @salesforce/sfdx-lwc-jest: 4.0.1
  • Node: 20.9.0

Possible Solution

Add a new stub for the toast module

@freddysilber
Copy link
Author

I'm happy to submit a PR for this

@Mrgagne
Copy link

Mrgagne commented May 20, 2024

@freddysilber You might need to add it to a custom jest.config.js file, similar to this.
https://github.com/trailheadapps/lwc-recipes/blob/main/jest.config.js

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

No branches or pull requests

2 participants