diff --git a/src/components/super/i-block/event/test/unit/api.ts b/src/components/super/i-block/event/test/unit/api.ts index d70a1b84b1..794213c569 100644 --- a/src/components/super/i-block/event/test/unit/api.ts +++ b/src/components/super/i-block/event/test/unit/api.ts @@ -11,6 +11,7 @@ import test from 'tests/config/unit/test'; import { renderDummy } from 'components/super/i-block/event/test/helpers'; import type bDummy from 'components/dummies/b-dummy/b-dummy'; +import { BOM, Component } from 'tests/helpers'; test.describe(' event API', () => { const componentName = 'b-dummy'; @@ -22,6 +23,38 @@ test.describe(' event API', () => { }, componentName); }); + test('the event handler should be removed by using off and providing cb', async ({page}) => { + const dummy = await Component.createComponent(page, 'b-dummy'); + + await dummy.evaluate((ctx) => { + ctx.testComponent = 'b-button-functional'; + }); + + const childComponent = await Component.waitForComponentByQuery(page, '.b-button'); + + await childComponent.evaluate((ctx) => { + const dummy = ctx.$normalParent; + + const handler = () => { + globalThis.testResult = true; + }; + + dummy?.once('hook:deactivated', handler); + + ctx.unsafe.async.worker(() => { + dummy?.off('hook:deactivated', handler); + }); + }); + + await BOM.waitForIdleCallback(page); + await childComponent.evaluate((ctx) => ctx.unsafe.$destroy()); + await BOM.waitForIdleCallback(page); + await dummy.evaluate((ctx) => ctx.deactivate()); + await BOM.waitForIdleCallback(page); + + await test.expect(page.evaluate(() => globalThis.testResult)).resolves.toBeUndefined(); + }); + test('the event passed to `emit` should be normalized to camelCase', async ({page}) => { const target = await renderDummy(page);