Skip to content

Commit ceaded6

Browse files
committed
Section 32: Implementing WaitFor
1 parent 0f9c105 commit ceaded6

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

32-The-Basics-of-Testing/06-movies/test/autocomplete.test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
const waitFor= ((selector) => {
2+
return new Promise((resolve, reject) => {
3+
const interval = setInterval(() => {
4+
if (document.querySelector(selector)) {
5+
clearInterval(interval)
6+
clearInterval(timeout)
7+
resolve()
8+
}
9+
}, 30)
10+
11+
const timeout = setTimeout(() => {
12+
clearInterval(interval)
13+
reject()
14+
}, 2000)
15+
})
16+
})
17+
118
beforeEach(() => {
219
document.querySelectorAll('#target').innerHTML = ''
320
createAutoComplete({
@@ -35,6 +52,5 @@ it('After searching, dropdown opens up', async () => {
3552
await waitFor('.dropdown-item')
3653

3754
const dropdown = document.querySelector('.dropdown')
38-
3955
expect(dropdown.className).to.include('is-active')
4056
})

32-The-Basics-of-Testing/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,6 @@ https://www.chaijs.com/guide/styles/#expect
5555
Faking the event with mocha
5656
`document.querySelector('input').dispatchEvent(new Event('input'))`
5757

58-
## 14. 16 Holding Up Assertions
58+
## 14. 16 Holding Up Assertions
59+
60+
## 15. 17 Implementing WaitFor

0 commit comments

Comments
 (0)