Skip to content

Commit

Permalink
Merge pull request #54 from rastapasta/unit-tests
Browse files Browse the repository at this point in the history
Add unit tests for utils.normalize
  • Loading branch information
jaller94 committed Nov 19, 2018
2 parents 14628a8 + 62440a9 commit e47fe83
Showing 1 changed file with 34 additions and 15 deletions.
49 changes: 34 additions & 15 deletions src/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,45 @@ const utils = require('./utils');

describe('utils', () => {
describe('hex2rgb', () => {
test('#ff0000', () => {
expect(utils.hex2rgb('#ff0000')).toEqual([255,0,0]);
describe.each([
['#ff0000', 255, 0, 0],
['#ffff00', 255, 255, 0],
['#0000ff', 0, 0, 255],
['#112233', 17, 34, 51],
['#888', 136, 136, 136],
])('when given "%s"', (input, r, g, b) => {
test(`returns [${r},${g},${b}]`, () => {
expect(utils.hex2rgb(input)).toEqual([r, g, b]);
});
});
test('#ffff00', () => {
expect(utils.hex2rgb('#ffff00')).toEqual([255,255,0]);
});
test('#0000ff', () => {
expect(utils.hex2rgb('#0000ff')).toEqual([0,0,255]);
});
test('#112233', () => {
expect(utils.hex2rgb('#112233')).toEqual([17,34,51]);
});
test('#888', () => {
expect(utils.hex2rgb('#888')).toEqual([136,136,136]);
});
test('33', () => {

test('throws an Error when given "33"', () => {
function wrapper() {
utils.hex2rgb('33');
}
expect(wrapper).toThrowError('isn\'t a supported hex color');
});
});
});

describe('normalize', () => {
describe.each([
[0, 0, 0, 0],
[61, 48, 61, 48],
[-61, -48, -61, -48],
[181, 85.06, -179, 85.0511],
[-181, -85.06, 179, -85.0511],
])('when given lon=%f and lat=%f', (lon, lat, expected_lon, expected_lat) => {
const input = {
lon,
lat,
};
test(`returns lon=${expected_lon} and lat=${expected_lat}`, () => {
const expected = {
lon: expected_lon,
lat: expected_lat,
};
expect(utils.normalize(input)).toEqual(expected);
});
});
});

0 comments on commit e47fe83

Please sign in to comment.