All files / stories/MockRequests/ExternalTests index.cy.tsx

100% Statements 17/17
100% Branches 0/0
100% Functions 6/6
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36          4x   4x 4x 4x 4x     4x   3x     3x 3x 3x   3x     4x   2x 2x 2x 2x   2x      
import { composeStories } from "@storybook/react";
import React from "react";
import { mockToCyIntercept } from "orphic-cypress";
import * as stories from "./index.stories";
 
const { WillFetch } = composeStories(stories);
 
describe("ExternalTests", () => {
  it("should fail if no interception provided", () => {
    cy.mount(<WillFetch />);
    cy.dataCy("button").should("contain", "Not Found!");
  });
 
  it("should be okay with a manual intercept", () => {
    // this could also happen in a beforeEach etc
    cy.intercept("GET", "/api/label", { body: { data: "Manual" } }).as(
      "manual"
    );
    cy.mount(<WillFetch />);
    cy.wait("@manual").then((interception) => {
      expect(interception.response!.body).to.deep.equal({ data: "Manual" });
    });
    cy.dataCy("button").should("contain", "Manual");
  });
 
  it("should be okay after calling mockToCyIntercept util with component's mockData", () => {
    // could also happen in a beforeEach etc
    mockToCyIntercept(WillFetch.parameters!.mockData);
    cy.mount(<WillFetch />);
    cy.wait("@/api/label").then((interception) => {
      expect(interception.response!.body).to.deep.equal({ data: "Loaded" });
    });
    cy.dataCy("button").should("contain", "Loaded");
  });
});