Skip to content

Commit

Permalink
test: improve code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
stepankuzmin committed Apr 8, 2019
1 parent ab7e852 commit 4a07311
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
34 changes: 31 additions & 3 deletions src/__mocks__/mapbox-gl.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,26 @@ Map.prototype.setStyle = jest.fn();

Map.prototype.addSource = function addSource(name, source) {
this._sources[name] = source;
this.style.sourceCaches[name] = {
clearTiles: jest.fn()
};
};

Map.prototype.getSource = function getSource(name) {
if (!this._sources[name]) {
return undefined;
}

return { ...this._sources[name], setData: jest.fn(), load: jest.fn() };
const source = {
setData: jest.fn(),
load: jest.fn(),
_tileJSONRequest: {
cancel: jest.fn()
},
...this._sources[name]
};

return source;
};

Map.prototype.removeSource = function removeSource(name) {
Expand Down Expand Up @@ -101,7 +113,15 @@ Map.prototype.getBounds = () => new LngLatBounds();
function Popup() {
this.setLngLat = jest.fn(() => this);
this.getLngLat = jest.fn(() => this);
this.addTo = jest.fn(() => this);

this.addTo = jest.fn((map) => {
if (!map) {
throw new Error();
}

return this;
});

this.setDOMContent = jest.fn(() => this);
this.remove = jest.fn();

Expand All @@ -115,7 +135,15 @@ Popup.prototype.on = function on(listener, fn) {
function Marker() {
this.setLngLat = jest.fn(() => this);
this.getLngLat = jest.fn(() => this);
this.addTo = jest.fn(() => this);

this.addTo = jest.fn((map) => {
if (!map) {
throw new Error();
}

return this;
});

this.remove = jest.fn();

return this;
Expand Down
2 changes: 2 additions & 0 deletions src/components/Layer/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ test('handlers', () => {
});

expect(handler).toHaveBeenCalledTimes(4);

// wrapper.setProps({ children: [] });
});

test('throws', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Marker/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test('update', () => {
});
});

test.skip('throws', () => {
test('throws', () => {
console.error = jest.fn();

expect(() =>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Popup/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test('update', () => {
});
});

test.skip('throws', () => {
test('throws', () => {
console.error = jest.fn();

expect(() =>
Expand Down
2 changes: 2 additions & 0 deletions src/components/Source/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ test('remove and add new source', () => {
test('throws', () => {
console.error = jest.fn();
const data = { type: 'FeatureCollection', features: [] };

expect(() =>
mount(<Source id="test" type="geojson" data={data} />)
).toThrow();

expect(console.error).toHaveBeenCalled();
});

0 comments on commit 4a07311

Please sign in to comment.