-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathindex.test.js
73 lines (58 loc) · 1.68 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* eslint-disable no-console */
import React from 'react';
import { mount } from 'enzyme';
import MapGL, { Image } from '../..';
test('render', () => {
const wrapper = mount(
<MapGL latitude={0} longitude={0} zoom={0}>
<Image id="test" image="test" />
<Image id="test1" image={{}} />
</MapGL>
);
expect(wrapper.find('Image').exists()).toBe(true);
expect(wrapper.find('Image')).toHaveLength(2);
wrapper.unmount();
expect(wrapper.find('Image').exists()).toBe(false);
});
test('update', () => {
const wrapper = mount(
<MapGL latitude={0} longitude={0} zoom={0}>
<Image id="test" image="test" />
<Image id="test1" image={{}} pixelRatio={1} sdf={false} />
</MapGL>
);
wrapper.setProps({
children: [
<Image id="test" image="test1" />,
<Image id="test1" image={{}} pixelRatio={3} sdf />
]
});
wrapper.setProps({
children: [
<Image id="test" image="test" />,
<Image id="test1" image={{}} pixelRatio={1} sdf={false} />
]
});
});
test('throws on loadImage', () => {
console.error = jest.fn();
/* eslint-disable global-require */
const mapboxgl = require('../../__mocks__/mapbox-gl');
mapboxgl.Map.prototype.loadImage = function loadImage(url, callback) {
callback(new Error());
};
jest.setMock('mapbox-gl', mapboxgl);
expect(() =>
mount(
<MapGL latitude={0} longitude={0} zoom={0}>
<Image id="test" image="will-fail" />
</MapGL>
)
).toThrow();
expect(console.error).toHaveBeenCalled();
});
test('throws', () => {
console.error = jest.fn();
expect(() => mount(<Image id="test" image="test" />)).toThrow();
expect(console.error).toHaveBeenCalled();
});