-
Notifications
You must be signed in to change notification settings - Fork 88
/
angularjs.test.js
36 lines (32 loc) · 978 Bytes
/
angularjs.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
import '@testing-library/jest-dom/extend-expect'
import {getQueriesForElement} from '@testing-library/dom'
import userEvent from '@testing-library/user-event'
import angular from 'angular'
angular.module('myApp', []).component('myCounter', {
template: `
<button ng-click="$ctrl.increment()">{{$ctrl.count}}</button>
`,
controller: function MyCounter() {
this.count = 0
this.increment = function () {
this.count += 1
}
},
})
function render(html, config) {
const container = document.createElement('div')
container.innerHTML = html
angular.bootstrap(container, config.modules)
return {
container,
...getQueriesForElement(container),
}
}
test('renders a counter', () => {
const {getByText} = render(`<my-counter></my-counter>`, {modules: ['myApp']})
const counter = getByText('0')
userEvent.click(counter)
expect(counter).toHaveTextContent('1')
userEvent.click(counter)
expect(counter).toHaveTextContent('2')
})