From 7b0807d17ee7d178304c294ff6ad2cad0e67a7eb Mon Sep 17 00:00:00 2001 From: LB Johnston Date: Fri, 13 Oct 2023 08:36:52 +1000 Subject: [PATCH] Update ActionController unit tests to use a setup function --- .../src/controllers/ActionController.test.js | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/client/src/controllers/ActionController.test.js b/client/src/controllers/ActionController.test.js index 6b8fdf0e85..94bf3f6a45 100644 --- a/client/src/controllers/ActionController.test.js +++ b/client/src/controllers/ActionController.test.js @@ -5,6 +5,15 @@ describe('ActionController', () => { let app; const oldWindowLocation = window.location; + const setup = async (html) => { + document.body.innerHTML = `
${html}
`; + + app = Application.start(); + app.register('w-action', ActionController); + + await Promise.resolve(); + }; + beforeAll(() => { delete window.location; @@ -23,19 +32,16 @@ describe('ActionController', () => { }); describe('post method', () => { - beforeEach(() => { - document.body.innerHTML = ` - `; - - app = Application.start(); - app.register('w-action', ActionController); + beforeEach(async () => { + await setup(` + `); }); it('it should allow for a form POST with created data', () => { @@ -54,8 +60,8 @@ describe('ActionController', () => { }); describe('click method', () => { - beforeEach(() => { - document.body.innerHTML = ` + beforeEach(async () => { + await setup(` `; - - app = Application.start(); - app.register('w-action', ActionController); + `); }); it('should call click method when button is clicked via Stimulus action', () => { @@ -84,15 +87,12 @@ describe('ActionController', () => { }); describe('redirect method', () => { - beforeEach(() => { - document.body.innerHTML = ` + beforeEach(async () => { + await setup(` `; - - app = Application.start(); - app.register('w-action', ActionController); + `); }); it('should have a redirect method that falls back to any element value', () => {