Skip to content

Commit df21506

Browse files
authored
[test] Migrate colorManipulator from assert to expect (#20792)
1 parent 7bd0fd0 commit df21506

File tree

1 file changed

+79
-83
lines changed

1 file changed

+79
-83
lines changed
Lines changed: 79 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assert } from 'chai';
1+
import { expect } from 'chai';
22
import consoleErrorMock from 'test/utils/consoleErrorMock';
33
import {
44
recomposeColor,
@@ -25,314 +25,310 @@ describe('utils/colorManipulator', () => {
2525

2626
describe('recomposeColor', () => {
2727
it('converts a decomposed rgb color object to a string` ', () => {
28-
assert.strictEqual(
28+
expect(
2929
recomposeColor({
3030
type: 'rgb',
3131
values: [255, 255, 255],
3232
}),
33-
'rgb(255, 255, 255)',
34-
);
33+
).to.equal('rgb(255, 255, 255)');
3534
});
3635

3736
it('converts a decomposed rgba color object to a string` ', () => {
38-
assert.strictEqual(
37+
expect(
3938
recomposeColor({
4039
type: 'rgba',
4140
values: [255, 255, 255, 0.5],
4241
}),
43-
'rgba(255, 255, 255, 0.5)',
44-
);
42+
).to.equal('rgba(255, 255, 255, 0.5)');
4543
});
4644

4745
it('converts a decomposed hsl color object to a string` ', () => {
48-
assert.strictEqual(
46+
expect(
4947
recomposeColor({
5048
type: 'hsl',
5149
values: [100, 50, 25],
5250
}),
53-
'hsl(100, 50%, 25%)',
54-
);
51+
).to.equal('hsl(100, 50%, 25%)');
5552
});
5653

5754
it('converts a decomposed hsla color object to a string` ', () => {
58-
assert.strictEqual(
55+
expect(
5956
recomposeColor({
6057
type: 'hsla',
6158
values: [100, 50, 25, 0.5],
6259
}),
63-
'hsla(100, 50%, 25%, 0.5)',
64-
);
60+
).to.equal('hsla(100, 50%, 25%, 0.5)');
6561
});
6662
});
6763

6864
describe('hexToRgb', () => {
6965
it('converts a short hex color to an rgb color` ', () => {
70-
assert.strictEqual(hexToRgb('#9f3'), 'rgb(153, 255, 51)');
66+
expect(hexToRgb('#9f3')).to.equal('rgb(153, 255, 51)');
7167
});
7268

7369
it('converts a long hex color to an rgb color` ', () => {
74-
assert.strictEqual(hexToRgb('#a94fd3'), 'rgb(169, 79, 211)');
70+
expect(hexToRgb('#a94fd3')).to.equal('rgb(169, 79, 211)');
7571
});
7672
});
7773

7874
describe('rgbToHex', () => {
7975
it('converts an rgb color to a hex color` ', () => {
80-
assert.strictEqual(rgbToHex('rgb(169, 79, 211)'), '#a94fd3');
76+
expect(rgbToHex('rgb(169, 79, 211)')).to.equal('#a94fd3');
8177
});
8278

8379
it('idempotent', () => {
84-
assert.strictEqual(rgbToHex('#A94FD3'), '#A94FD3');
80+
expect(rgbToHex('#A94FD3')).to.equal('#A94FD3');
8581
});
8682
});
8783

8884
describe('hslToRgb', () => {
8985
it('converts an hsl color to an rgb color` ', () => {
90-
assert.strictEqual(hslToRgb('hsl(281, 60%, 57%)'), 'rgb(169, 80, 211)');
86+
expect(hslToRgb('hsl(281, 60%, 57%)')).to.equal('rgb(169, 80, 211)');
9187
});
9288

9389
it('converts an hsla color to an rgba color` ', () => {
94-
assert.strictEqual(hslToRgb('hsla(281, 60%, 57%, 0.5)'), 'rgba(169, 80, 211, 0.5)');
90+
expect(hslToRgb('hsla(281, 60%, 57%, 0.5)')).to.equal('rgba(169, 80, 211, 0.5)');
9591
});
9692

9793
it('allow to convert values only', () => {
98-
assert.deepEqual(hslToRgb(decomposeColor('hsl(281, 60%, 57%)')), 'rgb(169, 80, 211)');
94+
expect(hslToRgb(decomposeColor('hsl(281, 60%, 57%)'))).to.equal('rgb(169, 80, 211)');
9995
});
10096
});
10197

10298
describe('decomposeColor', () => {
10399
it('converts an rgb color string to an object with `type` and `value` keys', () => {
104100
const { type, values } = decomposeColor('rgb(255, 255, 255)');
105-
assert.strictEqual(type, 'rgb');
106-
assert.deepEqual(values, [255, 255, 255]);
101+
expect(type).to.equal('rgb');
102+
expect(values).to.deep.equal([255, 255, 255]);
107103
});
108104

109105
it('converts an rgba color string to an object with `type` and `value` keys', () => {
110106
const { type, values } = decomposeColor('rgba(255, 255, 255, 0.5)');
111-
assert.strictEqual(type, 'rgba');
112-
assert.deepEqual(values, [255, 255, 255, 0.5]);
107+
expect(type).to.equal(type, 'rgba');
108+
expect(values).to.deep.equal([255, 255, 255, 0.5]);
113109
});
114110

115111
it('converts an hsl color string to an object with `type` and `value` keys', () => {
116112
const { type, values } = decomposeColor('hsl(100, 50%, 25%)');
117-
assert.strictEqual(type, 'hsl');
118-
assert.deepEqual(values, [100, 50, 25]);
113+
expect(type).to.equal(type, 'hsl');
114+
expect(values).to.deep.equal([100, 50, 25]);
119115
});
120116

121117
it('converts an hsla color string to an object with `type` and `value` keys', () => {
122118
const { type, values } = decomposeColor('hsla(100, 50%, 25%, 0.5)');
123-
assert.strictEqual(type, 'hsla');
124-
assert.deepEqual(values, [100, 50, 25, 0.5]);
119+
expect(type).to.equal(type, 'hsla');
120+
expect(values).to.deep.equal([100, 50, 25, 0.5]);
125121
});
126122

127123
it('idempotent', () => {
128124
const output1 = decomposeColor('hsla(100, 50%, 25%, 0.5)');
129125
const output2 = decomposeColor(output1);
130-
assert.strictEqual(output1, output2);
126+
expect(output1).to.deep.equal(output2);
131127
});
132128
});
133129

134130
describe('getContrastRatio', () => {
135131
it('returns a ratio for black : white', () => {
136-
assert.strictEqual(getContrastRatio('#000', '#FFF'), 21);
132+
expect(getContrastRatio('#000', '#FFF')).to.equal(21);
137133
});
138134

139135
it('returns a ratio for black : black', () => {
140-
assert.strictEqual(getContrastRatio('#000', '#000'), 1);
136+
expect(getContrastRatio('#000', '#000')).to.equal(1);
141137
});
142138

143139
it('returns a ratio for white : white', () => {
144-
assert.strictEqual(getContrastRatio('#FFF', '#FFF'), 1);
140+
expect(getContrastRatio('#FFF', '#FFF')).to.equal(1);
145141
});
146142

147143
it('returns a ratio for dark-grey : light-grey', () => {
148-
assert.approximately(getContrastRatio('#707070', '#E5E5E5'), 3.93, 0.01);
144+
expect(getContrastRatio('#707070', '#E5E5E5')).to.be.approximately(3.93, 0.01);
149145
});
150146

151147
it('returns a ratio for black : light-grey', () => {
152-
assert.approximately(getContrastRatio('#000', '#888'), 5.92, 0.01);
148+
expect(getContrastRatio('#000', '#888')).to.be.approximately(5.92, 0.01);
153149
});
154150
});
155151

156152
describe('getLuminance', () => {
157153
it('returns a valid luminance for rgb black', () => {
158-
assert.strictEqual(getLuminance('rgba(0, 0, 0)'), 0);
159-
assert.strictEqual(getLuminance('rgb(0, 0, 0)'), 0);
154+
expect(getLuminance('rgba(0, 0, 0)')).to.equal(0);
155+
expect(getLuminance('rgb(0, 0, 0)')).to.equal(0);
160156
});
161157

162158
it('returns a valid luminance for rgb white', () => {
163-
assert.strictEqual(getLuminance('rgba(255, 255, 255)'), 1);
164-
assert.strictEqual(getLuminance('rgb(255, 255, 255)'), 1);
159+
expect(getLuminance('rgba(255, 255, 255)')).to.equal(1);
160+
expect(getLuminance('rgb(255, 255, 255)')).to.equal(1);
165161
});
166162

167163
it('returns a valid luminance for rgb mid-grey', () => {
168-
assert.strictEqual(getLuminance('rgba(127, 127, 127)'), 0.212);
169-
assert.strictEqual(getLuminance('rgb(127, 127, 127)'), 0.212);
164+
expect(getLuminance('rgba(127, 127, 127)')).to.equal(0.212);
165+
expect(getLuminance('rgb(127, 127, 127)')).to.equal(0.212);
170166
});
171167

172168
it('returns a valid luminance for an rgb color', () => {
173-
assert.strictEqual(getLuminance('rgb(255, 127, 0)'), 0.364);
169+
expect(getLuminance('rgb(255, 127, 0)')).to.equal(0.364);
174170
});
175171

176172
it('returns a valid luminance from an hsl color', () => {
177-
assert.strictEqual(getLuminance('hsl(100, 100%, 50%)'), 0.735);
173+
expect(getLuminance('hsl(100, 100%, 50%)')).to.equal(0.735);
178174
});
179175

180176
it('returns an equal luminance for the same color in different formats', () => {
181177
const hsl = 'hsl(100, 100%, 50%)';
182178
const rgb = 'rgb(85, 255, 0)';
183-
assert.strictEqual(getLuminance(hsl), getLuminance(rgb));
179+
expect(getLuminance(hsl)).to.equal(getLuminance(rgb));
184180
});
185181

186182
it('throw on invalid colors', () => {
187-
assert.throw(() => {
183+
expect(() => {
188184
getLuminance('black');
189-
}, 'unsupported `black` color');
185+
}).to.throw('unsupported `black` color');
190186
});
191187
});
192188

193189
describe('emphasize', () => {
194190
it('lightens a dark rgb color with the coefficient provided', () => {
195-
assert.strictEqual(emphasize('rgb(1, 2, 3)', 0.4), lighten('rgb(1, 2, 3)', 0.4));
191+
expect(emphasize('rgb(1, 2, 3)', 0.4)).to.equal(lighten('rgb(1, 2, 3)', 0.4));
196192
});
197193

198194
it('darkens a light rgb color with the coefficient provided', () => {
199-
assert.strictEqual(emphasize('rgb(250, 240, 230)', 0.3), darken('rgb(250, 240, 230)', 0.3));
195+
expect(emphasize('rgb(250, 240, 230)', 0.3)).to.equal(darken('rgb(250, 240, 230)', 0.3));
200196
});
201197

202198
it('lightens a dark rgb color with the coefficient 0.15 by default', () => {
203-
assert.strictEqual(emphasize('rgb(1, 2, 3)'), lighten('rgb(1, 2, 3)', 0.15));
199+
expect(emphasize('rgb(1, 2, 3)')).to.equal(lighten('rgb(1, 2, 3)', 0.15));
204200
});
205201

206202
it('darkens a light rgb color with the coefficient 0.15 by default', () => {
207-
assert.strictEqual(emphasize('rgb(250, 240, 230)'), darken('rgb(250, 240, 230)', 0.15));
203+
expect(emphasize('rgb(250, 240, 230)')).to.equal(darken('rgb(250, 240, 230)', 0.15));
208204
});
209205
});
210206

211207
describe('fade', () => {
212208
it('converts an rgb color to an rgba color with the value provided', () => {
213-
assert.strictEqual(fade('rgb(1, 2, 3)', 0.4), 'rgba(1, 2, 3, 0.4)');
209+
expect(fade('rgb(1, 2, 3)', 0.4)).to.equal('rgba(1, 2, 3, 0.4)');
214210
});
215211

216212
it('updates an rgba color with the alpha value provided', () => {
217-
assert.strictEqual(fade('rgba(255, 0, 0, 0.2)', 0.5), 'rgba(255, 0, 0, 0.5)');
213+
expect(fade('rgba(255, 0, 0, 0.2)', 0.5)).to.equal('rgba(255, 0, 0, 0.5)');
218214
});
219215

220216
it('converts an hsl color to an hsla color with the value provided', () => {
221-
assert.strictEqual(fade('hsl(0, 100%, 50%)', 0.1), 'hsla(0, 100%, 50%, 0.1)');
217+
expect(fade('hsl(0, 100%, 50%)', 0.1)).to.equal('hsla(0, 100%, 50%, 0.1)');
222218
});
223219

224220
it('updates an hsla color with the alpha value provided', () => {
225-
assert.strictEqual(fade('hsla(0, 100%, 50%, 0.2)', 0.5), 'hsla(0, 100%, 50%, 0.5)');
221+
expect(fade('hsla(0, 100%, 50%, 0.2)', 0.5)).to.equal('hsla(0, 100%, 50%, 0.5)');
226222
});
227223

228224
it('throw on invalid colors', () => {
229-
assert.throw(() => {
225+
expect(() => {
230226
fade('white', 0.4);
231-
}, 'unsupported `white` color');
227+
}).to.throw('unsupported `white` color');
232228
});
233229
});
234230

235231
describe('darken', () => {
236232
it("doesn't modify rgb black", () => {
237-
assert.strictEqual(darken('rgb(0, 0, 0)', 0.1), 'rgb(0, 0, 0)');
233+
expect(darken('rgb(0, 0, 0)', 0.1)).to.equal('rgb(0, 0, 0)');
238234
});
239235

240236
it("doesn't overshoot if an above-range coefficient is supplied", () => {
241-
assert.strictEqual(darken('rgb(0, 127, 255)', 1.5), 'rgb(0, 0, 0)');
242-
assert.strictEqual(consoleErrorMock.callCount(), 1);
237+
expect(darken('rgb(0, 127, 255)', 1.5)).to.equal('rgb(0, 0, 0)');
238+
expect(consoleErrorMock.callCount()).to.equal(1);
243239
});
244240

245241
it("doesn't overshoot if a below-range coefficient is supplied", () => {
246-
assert.strictEqual(darken('rgb(0, 127, 255)', -0.1), 'rgb(0, 127, 255)');
247-
assert.strictEqual(consoleErrorMock.callCount(), 1);
242+
expect(darken('rgb(0, 127, 255)', -0.1)).to.equal('rgb(0, 127, 255)');
243+
expect(consoleErrorMock.callCount()).to.equal(1);
248244
});
249245

250246
it('darkens rgb white to black when coefficient is 1', () => {
251-
assert.strictEqual(darken('rgb(255, 255, 255)', 1), 'rgb(0, 0, 0)');
247+
expect(darken('rgb(255, 255, 255)', 1)).to.equal('rgb(0, 0, 0)');
252248
});
253249

254250
it('retains the alpha value in an rgba color', () => {
255-
assert.strictEqual(darken('rgb(0, 0, 0, 0.5)', 0.1), 'rgb(0, 0, 0, 0.5)');
251+
expect(darken('rgb(0, 0, 0, 0.5)', 0.1)).to.equal('rgb(0, 0, 0, 0.5)');
256252
});
257253

258254
it('darkens rgb white by 10% when coefficient is 0.1', () => {
259-
assert.strictEqual(darken('rgb(255, 255, 255)', 0.1), 'rgb(229, 229, 229)');
255+
expect(darken('rgb(255, 255, 255)', 0.1)).to.equal('rgb(229, 229, 229)');
260256
});
261257

262258
it('darkens rgb red by 50% when coefficient is 0.5', () => {
263-
assert.strictEqual(darken('rgb(255, 0, 0)', 0.5), 'rgb(127, 0, 0)');
259+
expect(darken('rgb(255, 0, 0)', 0.5)).to.equal('rgb(127, 0, 0)');
264260
});
265261

266262
it('darkens rgb grey by 50% when coefficient is 0.5', () => {
267-
assert.strictEqual(darken('rgb(127, 127, 127)', 0.5), 'rgb(63, 63, 63)');
263+
expect(darken('rgb(127, 127, 127)', 0.5)).to.equal('rgb(63, 63, 63)');
268264
});
269265

270266
it("doesn't modify rgb colors when coefficient is 0", () => {
271-
assert.strictEqual(darken('rgb(255, 255, 255)', 0), 'rgb(255, 255, 255)');
267+
expect(darken('rgb(255, 255, 255)', 0)).to.equal('rgb(255, 255, 255)');
272268
});
273269

274270
it('darkens hsl red by 50% when coefficient is 0.5', () => {
275-
assert.strictEqual(darken('hsl(0, 100%, 50%)', 0.5), 'hsl(0, 100%, 25%)');
271+
expect(darken('hsl(0, 100%, 50%)', 0.5)).to.equal('hsl(0, 100%, 25%)');
276272
});
277273

278274
it("doesn't modify hsl colors when coefficient is 0", () => {
279-
assert.strictEqual(darken('hsl(0, 100%, 50%)', 0), 'hsl(0, 100%, 50%)');
275+
expect(darken('hsl(0, 100%, 50%)', 0)).to.equal('hsl(0, 100%, 50%)');
280276
});
281277

282278
it("doesn't modify hsl colors when l is 0%", () => {
283-
assert.strictEqual(darken('hsl(0, 50%, 0%)', 0.5), 'hsl(0, 50%, 0%)');
279+
expect(darken('hsl(0, 50%, 0%)', 0.5)).to.equal('hsl(0, 50%, 0%)');
284280
});
285281
});
286282

287283
describe('lighten', () => {
288284
it("doesn't modify rgb white", () => {
289-
assert.strictEqual(lighten('rgb(255, 255, 255)', 0.1), 'rgb(255, 255, 255)');
285+
expect(lighten('rgb(255, 255, 255)', 0.1)).to.equal('rgb(255, 255, 255)');
290286
});
291287

292288
it("doesn't overshoot if an above-range coefficient is supplied", () => {
293-
assert.strictEqual(lighten('rgb(0, 127, 255)', 1.5), 'rgb(255, 255, 255)');
294-
assert.strictEqual(consoleErrorMock.callCount(), 1);
289+
expect(lighten('rgb(0, 127, 255)', 1.5)).to.equal('rgb(255, 255, 255)');
290+
expect(consoleErrorMock.callCount()).to.equal(1);
295291
});
296292

297293
it("doesn't overshoot if a below-range coefficient is supplied", () => {
298-
assert.strictEqual(lighten('rgb(0, 127, 255)', -0.1), 'rgb(0, 127, 255)');
299-
assert.strictEqual(consoleErrorMock.callCount(), 1);
294+
expect(lighten('rgb(0, 127, 255)', -0.1)).to.equal('rgb(0, 127, 255)');
295+
expect(consoleErrorMock.callCount()).to.equal(1);
300296
});
301297

302298
it('lightens rgb black to white when coefficient is 1', () => {
303-
assert.strictEqual(lighten('rgb(0, 0, 0)', 1), 'rgb(255, 255, 255)');
299+
expect(lighten('rgb(0, 0, 0)', 1)).to.equal('rgb(255, 255, 255)');
304300
});
305301

306302
it('retains the alpha value in an rgba color', () => {
307-
assert.strictEqual(lighten('rgb(255, 255, 255, 0.5)', 0.1), 'rgb(255, 255, 255, 0.5)');
303+
expect(lighten('rgb(255, 255, 255, 0.5)', 0.1)).to.equal('rgb(255, 255, 255, 0.5)');
308304
});
309305

310306
it('lightens rgb black by 10% when coefficient is 0.1', () => {
311-
assert.strictEqual(lighten('rgb(0, 0, 0)', 0.1), 'rgb(25, 25, 25)');
307+
expect(lighten('rgb(0, 0, 0)', 0.1)).to.equal('rgb(25, 25, 25)');
312308
});
313309

314310
it('lightens rgb red by 50% when coefficient is 0.5', () => {
315-
assert.strictEqual(lighten('rgb(255, 0, 0)', 0.5), 'rgb(255, 127, 127)');
311+
expect(lighten('rgb(255, 0, 0)', 0.5)).to.equal('rgb(255, 127, 127)');
316312
});
317313

318314
it('lightens rgb grey by 50% when coefficient is 0.5', () => {
319-
assert.strictEqual(lighten('rgb(127, 127, 127)', 0.5), 'rgb(191, 191, 191)');
315+
expect(lighten('rgb(127, 127, 127)', 0.5)).to.equal('rgb(191, 191, 191)');
320316
});
321317

322318
it("doesn't modify rgb colors when coefficient is 0", () => {
323-
assert.strictEqual(lighten('rgb(127, 127, 127)', 0), 'rgb(127, 127, 127)');
319+
expect(lighten('rgb(127, 127, 127)', 0)).to.equal('rgb(127, 127, 127)');
324320
});
325321

326322
it('lightens hsl red by 50% when coefficient is 0.5', () => {
327-
assert.strictEqual(lighten('hsl(0, 100%, 50%)', 0.5), 'hsl(0, 100%, 75%)');
323+
expect(lighten('hsl(0, 100%, 50%)', 0.5)).to.equal('hsl(0, 100%, 75%)');
328324
});
329325

330326
it("doesn't modify hsl colors when coefficient is 0", () => {
331-
assert.strictEqual(lighten('hsl(0, 100%, 50%)', 0), 'hsl(0, 100%, 50%)');
327+
expect(lighten('hsl(0, 100%, 50%)', 0)).to.equal('hsl(0, 100%, 50%)');
332328
});
333329

334330
it("doesn't modify hsl colors when `l` is 100%", () => {
335-
assert.strictEqual(lighten('hsl(0, 50%, 100%)', 0.5), 'hsl(0, 50%, 100%)');
331+
expect(lighten('hsl(0, 50%, 100%)', 0.5)).to.equal('hsl(0, 50%, 100%)');
336332
});
337333
});
338334
});

0 commit comments

Comments
 (0)