sfdx-lwc-jest icon indicating copy to clipboard operation
sfdx-lwc-jest copied to clipboard

Cannot Find `lightning/toast` Module

Open freddysilber opened this issue 11 months ago • 2 comments

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 avatar Mar 19 '24 22:03 freddysilber