|
1 | 1 | import {expect, fixture, html} from '@open-wc/testing' |
2 | 2 | import {fake} from 'sinon' |
3 | | -import {controller} from '../src/controller.js' |
4 | | -import {bindShadow} from '../src/bind.js' |
| 3 | +import {actionable} from '../src/actionable.js' |
5 | 4 |
|
6 | 5 | describe('Actionable', () => { |
7 | | - @controller |
| 6 | + @actionable |
8 | 7 | class BindTestElement extends HTMLElement { |
9 | 8 | foo = fake() |
10 | 9 | bar = fake() |
11 | 10 | handleEvent = fake() |
12 | 11 | } |
| 12 | + window.customElements.define('bind-test', BindTestElement) |
13 | 13 | let instance: BindTestElement |
14 | 14 | beforeEach(async () => { |
15 | 15 | instance = await fixture(html`<bind-test data-action="foo:bind-test#foo"> |
@@ -126,7 +126,25 @@ describe('Actionable', () => { |
126 | 126 | el1.setAttribute('data-action', 'click:bind-test#foo') |
127 | 127 | el2.setAttribute('data-action', 'submit:bind-test#foo') |
128 | 128 | const shadowRoot = instance.attachShadow({mode: 'open'}) |
129 | | - bindShadow(shadowRoot) |
| 129 | + shadowRoot.append(el1, el2) |
| 130 | + |
| 131 | + // We need to wait for one microtask after injecting the HTML into to |
| 132 | + // controller so that the actions have been bound to the controller. |
| 133 | + await Promise.resolve() |
| 134 | + |
| 135 | + expect(instance.foo).to.have.callCount(0) |
| 136 | + el1.click() |
| 137 | + expect(instance.foo).to.have.callCount(1) |
| 138 | + el2.dispatchEvent(new CustomEvent('submit')) |
| 139 | + expect(instance.foo).to.have.callCount(2) |
| 140 | + }) |
| 141 | + |
| 142 | + it('can bind elements within a closed shadowDOM', async () => { |
| 143 | + const el1 = document.createElement('div') |
| 144 | + const el2 = document.createElement('div') |
| 145 | + el1.setAttribute('data-action', 'click:bind-test#foo') |
| 146 | + el2.setAttribute('data-action', 'submit:bind-test#foo') |
| 147 | + const shadowRoot = instance.attachShadow({mode: 'closed'}) |
130 | 148 | shadowRoot.append(el1, el2) |
131 | 149 |
|
132 | 150 | // We need to wait for one microtask after injecting the HTML into to |
@@ -158,7 +176,6 @@ describe('Actionable', () => { |
158 | 176 | const el1 = document.createElement('div') |
159 | 177 | const el2 = document.createElement('div') |
160 | 178 | const shadowRoot = instance.attachShadow({mode: 'open'}) |
161 | | - bindShadow(shadowRoot) |
162 | 179 | shadowRoot.append(el1, el2) |
163 | 180 |
|
164 | 181 | // We need to wait for one microtask after injecting the HTML into to |
|
0 commit comments