Skip to content

Instantly share code, notes, and snippets.

View t-lock's full-sized avatar

Timothy Wheelock t-lock

View GitHub Profile
@t-lock
t-lock / useMocks.js
Last active April 24, 2020 08:03
helper for mocking responses in puppeteer
export async function useMocks(page, mocks) {
await page.setRequestInterception(true);
page.on("request", async (request) => {
if (request.postData() && JSON.parse(request.postData()).operationName) {
const mock = mocks.find(
(mock) => mock.name === JSON.parse(request.postData()).operationName
);
if (mock) {
await delay(500);
request.respond({