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:
Cillian O'Ruanaidh
2022-02-11 10:21:26 +00:00
parent b43a68d717
commit 1b8c1bd27a
6 changed files with 33 additions and 22 deletions

View File

@@ -6,6 +6,11 @@ import { Application } from "stimulus";
import toggle_controller from "../../../app/webpacker/controllers/toggle_controller";
describe("ToggleController", () => {
beforeAll(() => {
const application = Application.start();
application.register("toggle", toggle_controller);
});
describe("#toggle", () => {
beforeEach(() => {
document.body.innerHTML = `<div data-controller="toggle">
@@ -14,9 +19,6 @@ describe("ToggleController", () => {
content
</div>
</div>`;
const application = Application.start();
application.register("toggle", toggle_controller);
});
it("toggle the content", () => {