Allow any number of onFetch handlers for a single test (#54846)
Recent usability testing indicated that it's convenient to register multiple `onFetch` handlers and iterate them until one of them response a result.
This commit is contained in:
parent
7b54e954c2
commit
826ef8c715
1 changed files with 3 additions and 4 deletions
|
@ -9,7 +9,7 @@ export interface NextFixture {
|
|||
}
|
||||
|
||||
class NextFixtureImpl implements NextFixture {
|
||||
private fetchHandler: FetchHandler | null = null
|
||||
private fetchHandlers: FetchHandler[] = []
|
||||
|
||||
constructor(
|
||||
public testId: string,
|
||||
|
@ -27,12 +27,11 @@ class NextFixtureImpl implements NextFixture {
|
|||
}
|
||||
|
||||
onFetch(handler: FetchHandler): void {
|
||||
this.fetchHandler = handler
|
||||
this.fetchHandlers.push(handler)
|
||||
}
|
||||
|
||||
private async handleFetch(request: Request): Promise<FetchHandlerResult> {
|
||||
const handler = this.fetchHandler
|
||||
if (handler) {
|
||||
for (const handler of this.fetchHandlers.slice().reverse()) {
|
||||
const result = handler(request)
|
||||
if (result) {
|
||||
return result
|
||||
|
|
Loading…
Reference in a new issue