-
-
Save mutaimwiti/aad17f41809faa7139f330d62338aafb to your computer and use it in GitHub Desktop.
Redux store testing with Playwright
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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