Skip to content

Commit

Permalink
Merge pull request #165 from marcalexiei/insert-style-test-serial
Browse files Browse the repository at this point in the history
test(insertStyle): ensures that tests are run in sequence
  • Loading branch information
elycruz authored Oct 17, 2024
2 parents 337cb2b + 045073d commit ee6f5e1
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 ee6f5e1

Please sign in to comment.