-
Notifications
You must be signed in to change notification settings - Fork 0
/
backbone.test.js
39 lines (36 loc) · 950 Bytes
/
backbone.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import '@testing-library/jest-dom/extend-expect'
import $ from 'jquery'
import Backbone from 'backbone'
import fromHTML from 'from-html/lib/from-html'
import {getQueriesForElement} from '@testing-library/dom'
import userEvent from '@testing-library/user-event'
const Counter = Backbone.View.extend({
initialize() {
this.count = 0
},
events: {
'click button': 'increment',
},
increment() {
this.count = this.count + 1
this.$el.find('button').text(this.count)
},
render() {
return this.$el.html(`
<div>
<button>${this.count}</button>
</div>
`)
},
})
// tests:
test.skip('counter increments', () => {
const div = document.createElement('div')
new Counter({el: div})
const {getByText} = getQueriesForElement(div)
const counter = getByText('0')
userEvent.click(counter)
expect(counter).toHaveTextContent('1')
userEvent.click(counter)
expect(counter).toHaveTextContent('2')
})