Skip to content

Commit

Permalink
chore: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sec-ant committed Jan 27, 2025
1 parent a41df05 commit b66785b
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions tests/polyfill.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,37 @@ describe("Polyfill doesn't take effect on existing non-nullable implementations"
test("existing string type implementation", async () => {
const placeholder = "";
globalThis.BarcodeDetector = placeholder;
const modulePath = `../src/polyfill?update=${Date.now()}}`;
await import(modulePath);
await import(/* @vite-ignore */ `../src/polyfill?update=${Date.now()}`);
assert.isTrue(Object.is(globalThis.BarcodeDetector, placeholder));
});
test("existing number type implementation", async () => {
const placeholder = 0;
globalThis.BarcodeDetector = placeholder;
const modulePath = `../src/polyfill?update=${Date.now()}}`;
await import(modulePath);
await import(/* @vite-ignore */ `../src/polyfill?update=${Date.now()}`);
assert.isTrue(Object.is(globalThis.BarcodeDetector, placeholder));
});
test("existing boolean type implementation", async () => {
const placeholder = false;
globalThis.BarcodeDetector = placeholder;
const modulePath = `../src/polyfill?update=${Date.now()}}`;
await import(modulePath);
await import(/* @vite-ignore */ `../src/polyfill?update=${Date.now()}`);
assert.isTrue(Object.is(globalThis.BarcodeDetector, placeholder));
});
test("existing document.all type implementation", async () => {
const placeholder = document.all;
globalThis.BarcodeDetector = placeholder;
const modulePath = `../src/polyfill?update=${Date.now()}}`;
await import(modulePath);
await import(/* @vite-ignore */ `../src/polyfill?update=${Date.now()}`);
assert.isTrue(Object.is(globalThis.BarcodeDetector, placeholder));
});
test("existing object type implementation", async () => {
const placeholder = Object.create(null);
globalThis.BarcodeDetector = placeholder;
const modulePath = `../src/polyfill?update=${Date.now()}}`;
await import(modulePath);
await import(/* @vite-ignore */ `../src/polyfill?update=${Date.now()}`);
assert.isTrue(Object.is(globalThis.BarcodeDetector, placeholder));
});
test("existing function type implementation", async () => {
const placeholder = () => {};
globalThis.BarcodeDetector = placeholder;
const modulePath = `../src/polyfill?update=${Date.now()}}`;
await import(modulePath);
await import(/* @vite-ignore */ `../src/polyfill?update=${Date.now()}`);
assert.isTrue(Object.is(globalThis.BarcodeDetector, placeholder));
});
});
Expand All @@ -63,20 +57,17 @@ describe("Polyfill takes effect on nullable implementations", () => {
test("existing implementation is deleted", async () => {
// biome-ignore lint/performance/noDelete: for testing
delete globalThis.BarcodeDetector;
const modulePath = `../src/polyfill?update=${Date.now()}}`;
await import(modulePath);
await import(/* @vite-ignore */ `../src/polyfill?update=${Date.now()}`);
assert.instanceOf(globalThis.BarcodeDetector, Function);
});
test("existing implementation is undefined", async () => {
globalThis.BarcodeDetector = undefined;
const modulePath = `../src/polyfill?update=${Date.now()}}`;
await import(modulePath);
await import(/* @vite-ignore */ `../src/polyfill?update=${Date.now()}`);
assert.instanceOf(globalThis.BarcodeDetector, Function);
});
test("existing implementation is null", async () => {
globalThis.BarcodeDetector = null;
const modulePath = `../src/polyfill?update=${Date.now()}}`;
await import(modulePath);
await import(/* @vite-ignore */ `../src/polyfill?update=${Date.now()}`);
assert.instanceOf(globalThis.BarcodeDetector, Function);
});
});

0 comments on commit b66785b

Please sign in to comment.