forked from kentcdodds/dom-testing-library-with-anything
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular.test.ts
45 lines (36 loc) · 1.1 KB
/
angular.test.ts
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
40
41
42
43
44
45
import 'jest-preset-angular'
import '@testing-library/jest-dom/extend-expect'
import {TestBed, ComponentFixtureAutoDetect} from '@angular/core/testing'
import {Component} from '@angular/core'
import {getQueriesForElement} from '@testing-library/dom'
import userEvent from '@testing-library/user-event'
@Component({
template: `
<div>
<button (click)="increment()">{{ count }}</button>
</div>
`,
})
export class AppComponent {
count = 0
private increment() {
this.count = this.count + 1
}
}
function render(component: any) {
TestBed.configureTestingModule({
declarations: [component],
providers: [{provide: ComponentFixtureAutoDetect, useValue: true}],
}).compileComponents()
const fixture = TestBed.createComponent(component)
const container = fixture.debugElement.nativeElement
return getQueriesForElement(container)
}
test('renders a counter', () => {
const {getByText} = render(AppComponent)
const counter = getByText('0')
userEvent.click(counter)
expect(counter).toHaveTextContent('1')
userEvent.click(counter)
expect(counter).toHaveTextContent('2')
})