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

Add Flowsupport stub into lightning stubs

Open jefersonchaves opened this issue 4 years ago • 4 comments
trafficstars

Description

Steps to Reproduce

// simplified test case
it('navigates to next event ...', () => {
    ...
});
// JS for component under test
import { LightningElement } from 'lwc';
import { FlowNavigationNextEvent } from "lightning/flowSupport";

export default class Foo extends LightningElement {
    goToNextStep() {
        this.dispatchEvent(new FlowNavigationNextEvent());
    }
}

Expected Results

Being able to test components that use lightning/flowSupport and potentially validate that event was dispatched.

Actual Results

Cannot find module 'lightning/flowSupport' from 'force-app'

Version

  • @salesforce/sfdx-lwc-jest: 1.0.1
  • Node: 14.17.5

Possible Solution

I currently added the following stub but is incomplete and requires duplication for the projects - I can happily submit a pull request for review (this was my starting point):

export const FlowAttributeChangeEventName = 'lightning__flowattributechange';

export class FlowAttributeChangeEvent extends CustomEvent {
 constructor(attributeName, attributeValue) {
    super(FlowAttributeChangeEventName, {
        composed: true,
        cancelable: true,
        bubbles: true,
        detail: {
            attributeName,
            attributeValue
        }
    });
  }
}

export const FlowNavigationNextEventName = 'lightning__flownextevent';

export class FlowNavigationNextEvent extends CustomEvent {
 constructor(attributeName, attributeValue) {
    super(FlowNavigationNextEventName, {
        composed: true,
        cancelable: true,
        bubbles: true,
        detail: {
            attributeName,
            attributeValue
        }
    });
  }
}

jefersonchaves avatar Sep 16 '21 17:09 jefersonchaves

@jefersonchaves Would you mind sharing your completed stub? I assume you completed your stub since then, but I can't seem to find your PR. It would really help me :) thanks. If you can't, the above is still a good starting point.

PS. its kind of crazy that no one has responded to such a needed issue

djsing avatar May 08 '22 21:05 djsing

Hello @djsing - To be honest I got involved into other projects and I feel I have never submitted a PR. The starting point still what I described here. I hope it helps you.

jefersonchaves avatar May 08 '22 21:05 jefersonchaves

with the release of the lightning/flow module it would be great if that could be supported as well.

rgoodman22 avatar Feb 23 '23 13:02 rgoodman22

Is this ever intended to be doable, and if not what alternative for testing is officially recommended?

goto-dev-null avatar Dec 15 '23 22:12 goto-dev-null