Skip to content

Instantly share code, notes, and snippets.

@mutaimwiti
Forked from arjunattam/redux.test.js
Created September 1, 2021 01:17
Show Gist options
  • Save mutaimwiti/aad17f41809faa7139f330d62338aafb to your computer and use it in GitHub Desktop.
Save mutaimwiti/aad17f41809faa7139f330d62338aafb to your computer and use it in GitHub Desktop.
Redux store testing with Playwright
const pw = require('playwright');
(async () => {
const browser = await pw.chromium.launch();
const context = await browser.newContext();
// set addInitScript to run this on every page load in this context
// in the app, use window.IS_PLAYWRIGHT to set window.store = store;
await context.addInitScript('window.IS_PLAYWRIGHT = true;')
const page = await context.newPage();
await page.goto('http://localhost:3000');
// evaluate in page context to get window.store, and
// then assert values in nodejs
console.log(await page.evaluate(() => window.store.getState()));
// dispatching actions to modify redux store
await page.evaluate(() => {
window.store.dispatch({ type: 'ADD_TODO', text: 'Test dispatch' });
});
console.log(await page.evaluate(() => window.store.getState()));
await browser.close();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment