|
| 1 | +import { ReactWrapper, ShallowWrapper } from "enzyme"; |
| 2 | +import * as React from "react"; |
| 3 | + |
| 4 | +import { Dummy } from "../test/Dummy"; |
| 5 | +import Wrapper from "./Wrapper"; |
| 6 | + |
| 7 | +describe("Wrapper", () => { |
| 8 | + describe("when using the different render methods", () => { |
| 9 | + const component = new Wrapper(Dummy).withDefaultProps({ |
| 10 | + value: "Default value" |
| 11 | + }); |
| 12 | + |
| 13 | + describe("when using 'shallow'", () => { |
| 14 | + const { wrapper } = component.shallow(); |
| 15 | + |
| 16 | + it("returns ShallowWrapper", () => { |
| 17 | + expect(wrapper).toBeInstanceOf(ShallowWrapper); |
| 18 | + }); |
| 19 | + |
| 20 | + it("has the correct root node", () => { |
| 21 | + expect(wrapper.instance()).toBeInstanceOf(Dummy); |
| 22 | + }); |
| 23 | + |
| 24 | + it("matches snapshot", () => { |
| 25 | + expect(wrapper).toMatchSnapshot(); |
| 26 | + }); |
| 27 | + }); |
| 28 | + |
| 29 | + describe("when using 'mount'", () => { |
| 30 | + const { wrapper } = component.mount(); |
| 31 | + |
| 32 | + it("returns ReactWrapper", () => { |
| 33 | + expect(wrapper).toBeInstanceOf(ReactWrapper); |
| 34 | + }); |
| 35 | + |
| 36 | + it("has the correct root node", () => { |
| 37 | + expect(wrapper.instance()).toBeInstanceOf(Dummy); |
| 38 | + }); |
| 39 | + |
| 40 | + it("matches snapshot", () => { |
| 41 | + expect(wrapper).toMatchSnapshot(); |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + describe("when using 'render'", () => { |
| 46 | + const { wrapper } = component.render(); |
| 47 | + |
| 48 | + it("returns Cheerio wrapper", () => { |
| 49 | + expect(wrapper.cheerio).toBe("[cheerio object]"); |
| 50 | + }); |
| 51 | + |
| 52 | + it("has the correct root node", () => { |
| 53 | + expect(wrapper.hasClass("Dummy")).toBe(true); |
| 54 | + }); |
| 55 | + |
| 56 | + it("matches snapshot", () => { |
| 57 | + expect(wrapper).toMatchSnapshot(); |
| 58 | + }); |
| 59 | + }); |
| 60 | + }); |
| 61 | + |
| 62 | + describe("when using the children API", () => { |
| 63 | + const component = new Wrapper(Dummy).withDefaultChildren( |
| 64 | + <div>Default children</div> |
| 65 | + ); |
| 66 | + |
| 67 | + it("renders default children correctly", () => { |
| 68 | + const { wrapper } = component.render(); |
| 69 | + |
| 70 | + expect(wrapper.find(".Dummy--children").html()).toBe( |
| 71 | + "<div>Default children</div>" |
| 72 | + ); |
| 73 | + }); |
| 74 | + |
| 75 | + it("renders test-specific children correctly", () => { |
| 76 | + const { wrapper } = component |
| 77 | + .withChildren(<span>Test children</span>) |
| 78 | + .render(); |
| 79 | + |
| 80 | + expect(wrapper.find(".Dummy--children").html()).toBe( |
| 81 | + "<span>Test children</span>" |
| 82 | + ); |
| 83 | + }); |
| 84 | + |
| 85 | + it("clears test-specific children after previous test and renders default children again", () => { |
| 86 | + const { wrapper } = component.render(); |
| 87 | + |
| 88 | + expect(wrapper.find(".Dummy--children").html()).toBe( |
| 89 | + "<div>Default children</div>" |
| 90 | + ); |
| 91 | + }); |
| 92 | + }); |
| 93 | + |
| 94 | + describe("when using the props API", () => { |
| 95 | + const component = new Wrapper(Dummy).withDefaultProps({ |
| 96 | + value: "Default value" |
| 97 | + }); |
| 98 | + |
| 99 | + it("renders with default props correctly", () => { |
| 100 | + const { wrapper } = component.render(); |
| 101 | + |
| 102 | + expect(wrapper.find(".Dummy--value").text()).toBe("Default value"); |
| 103 | + }); |
| 104 | + |
| 105 | + it("renders with test-specific props correctly", () => { |
| 106 | + const { wrapper } = component |
| 107 | + .withProps({ |
| 108 | + value: "Test value" |
| 109 | + }) |
| 110 | + .render(); |
| 111 | + |
| 112 | + expect(wrapper.find(".Dummy--value").text()).toBe("Test value"); |
| 113 | + }); |
| 114 | + |
| 115 | + it("clears test-specific props after previous test and uses default props again", () => { |
| 116 | + const { wrapper } = component.render(); |
| 117 | + |
| 118 | + expect(wrapper.find(".Dummy--value").text()).toBe("Default value"); |
| 119 | + }); |
| 120 | + }); |
| 121 | +}); |
0 commit comments