Skip to content

Commit 23bdd70

Browse files
muankeithamus
authored andcommitted
Add test case for element with connectedcallback bindings
1 parent 09f5ad5 commit 23bdd70

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

test/bind.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ describe('bind', () => {
162162
expect(instance.foo).to.have.been.called.exactly(0)
163163
})
164164

165-
it('will not re-bind elements that havent already had `bind()` called', async function () {
165+
it('will not bind elements that havent already had `bind()` called', async function () {
166166
customElements.define('bind-test-not-element', class BindTestNotController extends HTMLElement {})
167167
const instance = document.createElement('bind-test-not-element')
168168
chai.spy.on(instance, 'foo')
@@ -178,6 +178,29 @@ describe('bind', () => {
178178
button.click()
179179
expect(instance.foo).to.have.been.called.exactly(0)
180180
})
181+
182+
it.only('will not re-bind elements that just had `bind()` called', async function () {
183+
customElements.define(
184+
'bind-test-not-element',
185+
class BindTestNotController extends HTMLElement {
186+
connectedCallback() {
187+
bind(this)
188+
}
189+
}
190+
)
191+
const instance = document.createElement('bind-test-not-element')
192+
chai.spy.on(instance, 'foo')
193+
listenForBind(root)
194+
const button = document.createElement('button')
195+
button.setAttribute('data-action', 'click:bind-test-not-element#foo')
196+
instance.appendChild(button)
197+
root.appendChild(instance)
198+
// wait for processQueue
199+
await waitForNextAnimationFrame()
200+
await waitForNextAnimationFrame()
201+
button.click()
202+
expect(instance.foo).to.have.been.called.exactly(1)
203+
})
181204
})
182205

183206
it('re-binds actions deeply in the HTML', async function () {

0 commit comments

Comments
 (0)