From 045073dd6396987dfe22cac3b91670e1179b750a Mon Sep 17 00:00:00 2001 From: Marco Pasqualetti Date: Mon, 7 Oct 2024 17:13:02 +0200 Subject: [PATCH] test(insertStyle): ensures that tests are run in sequence --- test/insertStyle.test.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/test/insertStyle.test.ts b/test/insertStyle.test.ts index 6b8c413..e0fe6a2 100644 --- a/test/insertStyle.test.ts +++ b/test/insertStyle.test.ts @@ -5,7 +5,7 @@ import Sinon from 'sinon'; const expectA = 'body{color:red}'; -test('should insertStyle works', async (t) => { +test.serial('insertStyle should work in a DOM environment', async (t) => { const browser = new Browser(); const page = browser.newPage(); @@ -20,15 +20,29 @@ test('should insertStyle works', async (t) => { // --- // Remove overrides - t.teardown(() => { + t.teardown(async () => { Sinon.restore(); + + await browser.close(); }); // ----- // Execute the actual test + t.is( + Array.from(document.styleSheets).length, + 0, + 'Should not have stylesheets', + ); + const cssStr = insertStyle(expectA); + t.is( + Array.from(document.styleSheets).length, + 1, + 'Should include only `insertStyle` related stylesheet', + ); + const styleSheet = document.head.querySelector('style')!; t.is( styleSheet.textContent, @@ -40,10 +54,8 @@ test('should insertStyle works', async (t) => { 'text/css', 'Should contain `type` attrib. equal to "text/css"', ); - - await browser.close(); }); -test("insertStyle shouldn't choke when window is undefined", (t) => { - t.notThrows(() => insertStyle('css')); +test.serial("insertStyle shouldn't choke when window is undefined", (t) => { + t.notThrows(() => insertStyle(expectA)); });