Skip to content

Commit f42209d

Browse files
committed
Use real div elements instead of a fake one
1 parent 77048ec commit f42209d

1 file changed

Lines changed: 8 additions & 13 deletions

File tree

catalyst/test/bind.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import {bind} from '../lib/bind.js'
22

33
describe('bind', () => {
4-
class FakeElement {
5-
addEventListener() {}
6-
getAttribute() {}
7-
closest() {}
8-
}
94
class MyController {
105
get tagName() {
116
return 'my-controller'
@@ -25,7 +20,7 @@ describe('bind', () => {
2520
it('binds events on elements based on their data-action attribute', () => {
2621
const instance = new MyController()
2722
chai.spy.on(instance, 'foo')
28-
const el = new FakeElement()
23+
const el = document.createElement('div')
2924
instance.querySelectorAll = () => [el]
3025
el.closest = () => instance
3126
el.getAttribute = () => 'click:my-controller#foo'
@@ -42,7 +37,7 @@ describe('bind', () => {
4237
it('allows for the presence of `:` in an event name', () => {
4338
const instance = new MyController()
4439
chai.spy.on(instance, 'foo')
45-
const el = new FakeElement()
40+
const el = document.createElement('div')
4641
instance.querySelectorAll = () => [el]
4742
el.closest = () => instance
4843
el.getAttribute = () => 'custom:event:my-controller#foo'
@@ -76,7 +71,7 @@ describe('bind', () => {
7671
it('does not bind elements whose closest selector is not this controller', () => {
7772
const instance = new MyController()
7873
chai.spy.on(instance, 'foo')
79-
const el = new FakeElement()
74+
const el = document.createElement('div')
8075
instance.querySelectorAll = () => [el]
8176
el.closest = () => null
8277
el.getAttribute = () => 'click:my-controller#foo'
@@ -88,7 +83,7 @@ describe('bind', () => {
8883
it('does not bind elements whose data-action does not match controller tagname', () => {
8984
const instance = new MyController()
9085
chai.spy.on(instance, 'foo')
91-
const el = new FakeElement()
86+
const el = document.createElement('div')
9287
instance.querySelectorAll = () => [el]
9388
el.closest = () => null
9489
el.getAttribute = () => 'click:other-controller#foo'
@@ -100,7 +95,7 @@ describe('bind', () => {
10095
it('does not bind methods that dont exist', () => {
10196
const instance = new MyController()
10297
chai.spy.on(instance, 'foo')
103-
const el = new FakeElement()
98+
const el = document.createElement('div')
10499
instance.querySelectorAll = () => [el]
105100
el.closest = () => instance
106101
el.getAttribute = () => 'click:my-controller#frob'
@@ -112,7 +107,7 @@ describe('bind', () => {
112107
it('can bind multiple event types', () => {
113108
const instance = new MyController()
114109
chai.spy.on(instance, 'foo')
115-
const el = new FakeElement()
110+
const el = document.createElement('div')
116111
instance.querySelectorAll = () => [el]
117112
el.closest = () => instance
118113
el.getAttribute = () => 'click:my-controller#foo submit:my-controller#foo'
@@ -132,8 +127,8 @@ describe('bind', () => {
132127
it('can bind multiple elements to the same event', () => {
133128
const instance = new MyController()
134129
chai.spy.on(instance, 'foo')
135-
const el1 = new FakeElement()
136-
const el2 = new FakeElement()
130+
const el1 = document.createElement('div')
131+
const el2 = document.createElement('div')
137132
instance.querySelectorAll = () => [el1, el2]
138133
el1.closest = () => instance
139134
el2.closest = () => instance

0 commit comments

Comments
 (0)