for fake browser runtime environment in server-side render.
fake browser runtime environment in server-side render.
npm install ssr-polyfill --save
# or yarn add ssr-polyfill
in node env:
const ssrPolyfill = require('ssr-polyfill');
global.window = ssrPolyfill({
context: {
userInfo: 'hello',
}
});
global.self = global.window;
// maybe you can mock somewhere
// not use `window.document` use `document.*`
global.document = global.window.document;
// in client env `window.context` is { userInfo: 'hello' }
url
default is http://localhost
, you also change the location.pathname
use http://localhost/bar
html
init html template, default is <body><div id="root"></div></body>
window
objectnpm run test
Contributions, issues and feature requests are welcome!Feel free to check issues page.
Give a ⭐️ if this project helped you!
This project is ISC licensed.