Skip to content

Commit a6a9869

Browse files
committed
Fix tests
1 parent d821df7 commit a6a9869

File tree

4 files changed

+32
-20
lines changed

4 files changed

+32
-20
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@
6767
"coverageReporters": [
6868
"html",
6969
"text"
70-
]
70+
],
71+
"globals": {
72+
"window": {}
73+
}
7174
},
7275
"prettier": {
7376
"printWidth": 100,

test/MutationObserver.tests.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -538,19 +538,19 @@ describe('MutationObserver', () => {
538538
}
539539

540540
describe('synchronous usage', () => {
541-
Object.keys(cases).forEach((description) => {
541+
for (const description of Object.keys(cases)) {
542542
const testCase = cases[description];
543-
it(description, () => {
543+
it(description, async () => {
544544
const expected = testCase(observer) || [];
545545

546546
const records = observer.takeRecords();
547547
assertRecords(records, expected);
548548

549-
return waitForNextTask().then(() => {
550-
expect(callbackCalled).toBe(false);
551-
});
549+
await waitForNextTask();
550+
551+
expect(callbackCalled).toBe(false);
552552
});
553-
});
553+
}
554554
});
555555

556556
describe('asynchronous usage', () => {
@@ -563,22 +563,22 @@ describe('MutationObserver', () => {
563563
observer.disconnect();
564564
});
565565

566-
Object.keys(cases).forEach((description) => {
566+
for (const description of Object.keys(cases)) {
567567
const testCase = cases[description];
568-
it(description, () => {
568+
it(description, async () => {
569569
const expected = testCase(observer);
570570

571-
waitForNextTask().then(() => {
572-
if (expected !== null) {
573-
expect(callbackCalled).toBe(true);
574-
expect(calls.length).toBe(1);
575-
expect(calls[0].observer).toBe(observer);
576-
assertRecords(calls[0].records, expected);
577-
} else {
578-
expect(callbackCalled).toBe(false);
579-
}
580-
});
571+
await waitForNextTask();
572+
573+
if (expected !== null) {
574+
expect(callbackCalled).toBe(true);
575+
expect(calls.length).toBe(1);
576+
expect(calls[0].observer).toBe(observer);
577+
assertRecords(calls[0].records, expected);
578+
} else {
579+
expect(callbackCalled).toBe(false);
580+
}
581581
});
582-
});
582+
}
583583
});
584584
});

test/examples/sizzle/sizzle.tests.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as slimdom from '../../../src/index';
22

3+
import './windowStub';
4+
35
import Sizzle = require('sizzle');
46

57
describe('Example: sizzle integration', () => {

test/examples/sizzle/windowStub.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as slimdom from '../../../src/index';
2+
3+
// Sizzle is built to run in a browser, so you'll need to set up your build tooling to inject a
4+
// stub for the window global. Here, we'll stub it with a slimdom document.
5+
6+
declare var window: any;
7+
window.document = slimdom.document.implementation.createHTMLDocument();

0 commit comments

Comments
 (0)