Skip to content

Commit 94c10ce

Browse files
keithamuskoddsson
andcommitted
test: add belt & braces test for autoShadowRoot controller behaviour
This test is one of a few that will fail if shadowRoot binding is somehow refactored out. Co-authored-by: Kristján Oddsson <koddsson@gmail.com>
1 parent 9d6366d commit 94c10ce

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

test/controller.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,23 @@ describe('controller', () => {
5757

5858
expect(instance.foo).to.have.been.called(1)
5959
})
60+
61+
it('binds auto shadowRoots', async () => {
62+
controller(class ControllerBindAutoShadowElement extends HTMLElement {})
63+
const instance = document.createElement('controller-bind-auto-shadow')
64+
const template = document.createElement('template')
65+
template.setAttribute('data-shadowroot', 'open')
66+
// eslint-disable-next-line github/unescaped-html-literal
67+
template.innerHTML = '<button data-action="click:controller-bind-auto-shadow#foo"></button>'
68+
instance.appendChild(template)
69+
chai.spy.on(instance, 'foo')
70+
document.body.appendChild(instance)
71+
72+
expect(instance.shadowRoot).to.exist
73+
expect(instance).to.have.property('shadowRoot').not.equal(null)
74+
expect(instance.shadowRoot.children).to.have.lengthOf(1)
75+
instance.shadowRoot.querySelector('button').click()
76+
77+
expect(instance.foo).to.have.been.called(1)
78+
})
6079
})

0 commit comments

Comments
 (0)