[FIX] web: tests: make mock fetch almost sync (micro-tick)
Before this commit, a studio qunit test ("edit/delete menus")
sometimes failed on runbot, because it tried to click on a button
in a modal footer, but it found 3 of them, because another dialog
which was expected to be closed at that moment, was still opened.
There was no guarantee for the dialog to be closed because of the
way browser.fetch was mocked. The fetching part was ok, but the
function returned a Response object, whose `json` method is async
(setTimeout-like async, i.e. "real" ticks).
This commit mocks some functions of the returned Response instance
to ensure that, by calling nextTick after a click or whatever, the
fetch operation has been done, the body has been decoded, potential
renderings are finished and the DOM has been patched.
Runbot error 23054
closes odoo/odoo#143980
X-original-commit: 66ef3ae730a233dc510425e0a5baca2973de493e
Signed-off-by: Samuel Degueldre (sad) <sad@odoo.com>
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -167,7 +167,15 @@ export function makeMockFetch(mockRPC) {
|
||||
status = 500;
|
||||
}
|
||||
const blob = new Blob([JSON.stringify(res || {})], { type: "application/json" });
|
||||
return new Response(blob, { status });
|
||||
const response = new Response(blob, { status });
|
||||
// Mock some functions of the Response API to make them almost synchronous (micro-tick level)
|
||||
// as their native implementation is async (tick level), which can lead to undeterministic
|
||||
// errors as it breaks the hypothesis that calling nextTick after fetching data is enough
|
||||
// to see the result rendered in the DOM.
|
||||
response.json = () => Promise.resolve(JSON.parse(JSON.stringify(res || {})));
|
||||
response.text = () => Promise.resolve(String(res || {}));
|
||||
response.blob = () => Promise.resolve(blob);
|
||||
return response;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user