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)); });