Open birkskyum opened 18 hours ago
I can't really figure how to do some browser mocking in deno.
I'm using the node command like this, which works:
node --experimental-strip-types --test --import ./test/mock-browser.ts (link to code)
node --experimental-strip-types --test --import ./test/mock-browser.ts
But with deno i get:
deno test --no-check:
deno test --no-check
error: ReferenceError: document is not defined container: document.createElement("div"),
I have in my deno.json
"lib": [ "deno.window", "dom" ]
The mock-browser.ts being:
import MockBrowser from "mock-browser"; const mock = new MockBrowser.mocks.MockBrowser(); global.document = mock.getDocument(); global.window = {}; // Polyfill based on https://gist.github.com/paulirish/1579671 let lastTime = 0; global.requestAnimationFrame = function (fn) { const now = Date.now(); const nextTime = Math.max(lastTime + 16, now); setTimeout(() => fn(lastTime = nextTime), nextTime - now); };
For node compat, I believe I need a way to do a similar --import in deno test, or another way to give a setup file, which I believe vitest calls it
--import
I can't really figure how to do some browser mocking in deno.
I'm using the node command like this, which works:
node --experimental-strip-types --test --import ./test/mock-browser.ts
(link to code)But with deno i get:
deno test --no-check
:I have in my deno.json
The mock-browser.ts being:
For node compat, I believe I need a way to do a similar
--import
in deno test, or another way to give a setup file, which I believe vitest calls it