Debian Codegraph @

addons/web/static/tests/legacy/public/minimal_dom.js

raw symbols SCIP
1 /** @odoo-module **/
2 import { registerCleanup } from "@web/../tests/helpers/cleanup";
3 import { getFixture, nextTick } from "@web/../tests/helpers/utils";
4 import { DEBOUNCE, makeAsyncHandler, makeButtonHandler } from '@web/legacy/js/public/minimal_dom';
5
6 QUnit.module('core', {}, function () {
7
8 QUnit.module('MinimalDom');
9
10 QUnit.test('MakeButtonHandler does not retrigger the same error', async function (assert) {
11 assert.expect(1);
12 assert.expectErrors();
13
14 // create a target for the button handler
15 const fixture = getFixture();
16 const button = document.createElement("button");
17 fixture.appendChild(button);
18 registerCleanup(() => { button.remove(); });
19
20 // get a way to reject the promise later
21 let rejectPromise;
22 const buttonHandler = makeButtonHandler(() => new Promise((resolve, reject) => {
23 rejectPromise = reject;
24 }));
25
26 // trigger the handler
27 buttonHandler({ target: button });
28
29 // wait for the button effect has been applied before rejecting the promise
30 await new Promise(res => setTimeout(res, DEBOUNCE + 1));
31 rejectPromise(new Error("reject"));
32
33 // check that there was only one unhandledrejection error
34 await nextTick();
35 assert.verifyErrors(["reject"]);
36 });
37
38 QUnit.test('MakeAsyncHandler does not retrigger the same error', async function (assert) {
39 assert.expect(1);
40 assert.expectErrors();
41
42 // get a way to reject the promise later
43 let rejectPromise;
44 const asyncHandler = makeAsyncHandler(() => new Promise((resolve, reject) => {
45 rejectPromise = reject;
46 }));
47
48 // trigger the handler
49 asyncHandler();
50
51 rejectPromise(new Error("reject"));
52
53 // check that there was only one unhandledrejection error
54 await nextTick();
55 assert.verifyErrors(["reject"]);
56 });
57 });