Skip to content

Commit 8783101

Browse files
committed
fix: use a promise, no function, to implement waitFor
1 parent 5500228 commit 8783101

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

packages/fetch-mock/src/Route.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,11 @@ class Route {
202202

203203
waitFor(awaitedRoute: Route) {
204204
const { response } = this.config;
205-
this.config.response = () => {
206-
return new Promise((res) =>
207-
awaitedRoute.onRespond(() => {
208-
res(response);
209-
}),
210-
);
211-
};
205+
this.config.response = new Promise((res) =>
206+
awaitedRoute.onRespond(() => {
207+
res(response);
208+
}),
209+
);
212210
}
213211

214212
onRespond(func: () => void) {

packages/fetch-mock/src/__tests__/FetchMock/response-negotiation.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe('response negotiation', () => {
143143
fm.fetchHandler('http://b.com').then(() => routesCalled.push('b')),
144144
fm.fetchHandler('http://a.com').then(() => routesCalled.push('a')),
145145
]);
146-
expect(routesCalled).toEqual(['a', 'c', 'b']);
146+
expect(routesCalled).toEqual(['a', 'b', 'c']);
147147
});
148148
it('Can chain waits', async () => {
149149
fm.route('http://a.com', 200, 'route-a')

0 commit comments

Comments
 (0)