mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Only initialise Stimulus app once in Jest tests in :beforeAll rather than :beforeEach
Before there was an issue with the remote_toggle_controller tests, which contains two tests. If you commented out one test and ran the other it would pass and vice versa but if both tests were uncommented only the first test would ever pass, the second one would fail. See https://github.com/openfoodfoundation/openfoodnetwork/pull/8805#discussion_r801464322 Co-authored-by: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com>
This commit is contained in:
@@ -6,6 +6,11 @@ import { Application } from "stimulus";
|
||||
import remote_toggle_controller from "../../../app/webpacker/controllers/remote_toggle_controller";
|
||||
|
||||
describe("RemoteToggleController", () => {
|
||||
beforeAll(() => {
|
||||
const application = Application.start();
|
||||
application.register("remote-toggle", remote_toggle_controller);
|
||||
});
|
||||
|
||||
describe("#toggle", () => {
|
||||
beforeEach(() => {
|
||||
document.body.innerHTML = `
|
||||
@@ -17,9 +22,6 @@ describe("RemoteToggleController", () => {
|
||||
</div>
|
||||
<div id="content">...</div>
|
||||
`;
|
||||
|
||||
const application = Application.start();
|
||||
application.register("remote-toggle", remote_toggle_controller);
|
||||
});
|
||||
|
||||
it("clicking a toggle switches the visibility of the :data-remote-toggle-selector element", () => {
|
||||
@@ -36,8 +38,7 @@ describe("RemoteToggleController", () => {
|
||||
expect(content.style.display).toBe("block");
|
||||
});
|
||||
|
||||
/* skipping, this test passes when it's the only test in this file but not otherwise? */
|
||||
it.skip("clicking a toggle with a chevron icon switches the visibility of content and the direction of the icon", () => {
|
||||
it("clicking a toggle with a chevron icon switches the visibility of content and the direction of the icon", () => {
|
||||
const button = document.getElementById("remote-toggle-with-chevron");
|
||||
const chevron = button.querySelector("i");
|
||||
const content = document.getElementById("content");
|
||||
|
||||
Reference in New Issue
Block a user