overleaf/services/web/cypress/support/shared/commands/intercept-async.ts
Alf Eaton 390d7ed005 Merge pull request #12176 from overleaf/ae-syntex-tests
Improve synctex Cypress tests

GitOrigin-RevId: 282d26d344d8ae08f52b18ef4c12a4c311a6b7ff
2023-03-14 09:04:14 +00:00

17 lines
465 B
TypeScript

import { RouteHandler, RouteMatcher } from 'cypress/types/net-stubbing'
export const interceptAsync = (route: RouteMatcher, alias: string) => {
const deferred: { resolve: (value: RouteHandler) => void } = {
resolve: () => {},
}
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)
}