Created
October 2, 2019 14:01
-
-
Save GergKllai1/0b88f105bfae1a5261b928c6bb9ad4c7 to your computer and use it in GitHub Desktop.
An example of testing setTimeOut and useState hook rerender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { mount } from "enzyme"; | |
import FlashMessage from "./FlashMessage"; | |
import { act } from "react-dom/test-utils"; | |
describe("FlashMessage", () => { | |
let container, messageMock; | |
beforeEach(() => { | |
jest.useFakeTimers(); | |
messageMock = "Test message"; | |
container = mount(<FlashMessage message={messageMock} />); | |
}); | |
it("Renders component", () => { | |
expect(container.length).toEqual(1); | |
}); | |
it("Displays message", () => { | |
expect(container.text()).toEqual(messageMock); | |
}); | |
it("Displays message", () => { | |
act(() => { | |
jest.runAllTimers(); | |
container.update() | |
}); | |
expect(container.text()).toEqual(""); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment