Function stubStoryActions

  • Get argTypes from both the default export and the individual story. Useful for a per-component beforeEach or top-of-test declaration. Note that you'll want to return undefined from beforeEach

    describe("SomeComponent", () => {
    beforeEach(() => {
    stubStoryActions(SomeComponent, stories);
    });

    it("should render ok and call someAction on init", () => {
    cy.mount(<SomeComponent {...this.actions} />);
    cy.get("@actions").its("someAction").should("be.calledWith", "");
    });
    });
    it("should do something", () => {
    // could just be `const actions = { someAction: cy.stub(), ... }`
    const actions = stubStoryActions(SomeStory, stories);
    cy.mount(<SomeStory {...actions} />);
    cy.dataCy("something").click().then(() => {
    expect(actions.someAction).to.have.callCount(1);
    });
    // or without the promise
    cy.dataCy("something").click();
    cy.get("@actions").its("someAction").should("have.callCount", 2);
    });

    Mostly an internal detail: precedence order, 3 through end will have essentially the same effect

    1. explicitly provided args/props for story which will become spies
    2. explicitly provided args at default export which will become spies
    3. local argTypes action definition
    4. global argTypes action definition
    5. local argTypes regex definition
    6. global argTypes regex definition

    Type Parameters

    Parameters

    Returns WrappedActions