Skip to content

Commit

Permalink
test(insertStyle): ensures that tests are run in sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalexiei committed Oct 7, 2024
1 parent 337cb2b commit 045073d
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions test/insertStyle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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,
Expand All @@ -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));
});

0 comments on commit 045073d

Please sign in to comment.