overleaf/services/web/cypress/support/shared/commands/intercept-async.ts
Alf Eaton e0d327a3e8 Skip/improve flaky pdf tests (#13150)
GitOrigin-RevId: a98b145e86f325d1df79bdbcd1825ee5a3ca6def
2023-05-25 08:04:49 +00:00

19 lines
521 B
TypeScript

import { RouteHandler, RouteMatcher } from 'cypress/types/net-stubbing'
export const interceptAsync = (route: RouteMatcher, alias: string) => {
const deferred: { resolve: (value: RouteHandler) => void } = {
resolve: () => {
console.error('This should never be called')
},
}
const promise = new Promise<RouteHandler>(resolve => {
deferred.resolve = resolve
})
cy.intercept(route, req => {
return promise.then(response => req.reply(response))
}).as(alias)
return cy.wrap(deferred)
}