-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.test.js
59 lines (48 loc) · 1.33 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* globals describe, expect, it */
import {mount} from 'enzyme'
import {mountToJson} from 'enzyme-to-json'
import nock from 'nock'
import React from 'react'
import Geocoder from './index'
const mockAutocompleteResult = require('./mock-autocomplete-result.json')
// add a div to jsdom for enzyme to mount to
const div = document.createElement('div')
div.id = 'test'
document.body.appendChild(div)
function timeoutPromise (ms) {
return new Promise((resolve, reject) => {
setTimeout(resolve, ms)
})
}
describe('Geocoder', () => {
it('should render', () => {
const tree = mount(
<Geocoder
apiKey='test'
/>
, {
attachTo: document.getElementById('test')
})
expect(mountToJson(tree)).toMatchSnapshot()
})
it('should process input change', async () => {
nock('https://search.mapzen.com/')
.get(/v1\/autocomplete/)
.reply(200, mockAutocompleteResult)
const tree = mount(
<Geocoder
apiKey='test'
/>
, {
attachTo: document.getElementById('test')
})
let calculatedOptions
tree.find('Async').props().loadOptions('123 main', (error, result) => {
expect(error).toBeFalsy()
calculatedOptions = result
})
// wait for query to mapzen
await timeoutPromise(1000)
expect(calculatedOptions.options).toHaveLength(10)
})
})