From 9ef0d88d55f43fd74df244d7777fae669b1e30b8 Mon Sep 17 00:00:00 2001 From: Christian Paul Date: Sun, 18 Nov 2018 19:21:56 -0800 Subject: [PATCH] Improve utils.hex2rgb tests --- src/utils.spec.js | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/utils.spec.js b/src/utils.spec.js index fe946a9..3556001 100644 --- a/src/utils.spec.js +++ b/src/utils.spec.js @@ -3,22 +3,19 @@ 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'); }