Skip to content

Commit e79752b

Browse files
committed
Update colors test
1 parent c928a30 commit e79752b

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

src/utils/colors.test.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
11
import { times } from 'ramda';
2-
import { COLORS, getRandomColor } from './colors';
2+
import shuffle from 'shuffle-array';
3+
import { getRandomColor } from './colors';
34

45
describe('Colors Utils', () => {
56
describe('getRandomColor', () => {
6-
beforeAll(() => {
7-
jest.spyOn(Math, 'random').mockReturnValue(0.5);
8-
});
7+
describe('When getting the first color', () => {
8+
it('returns "#D84315"', () => {
9+
expect(getRandomColor()).toBe('#D84315');
10+
});
911

10-
afterAll(() => {
11-
Math.random.mockRestore();
12+
it('calls shuffle method', () => {
13+
expect(shuffle).toHaveBeenCalledTimes(1);
14+
});
1215
});
1316

14-
it('returns "#388E3C" on the first time', () => {
15-
expect(getRandomColor()).toBe('#388E3C');
16-
});
17+
describe('When getting the second color', () => {
18+
it('returns "#BF360C"', () => {
19+
expect(getRandomColor()).toBe('#BF360C');
20+
});
1721

18-
it('returns "#D84315" on the second time', () => {
19-
expect(getRandomColor()).toBe('#D84315');
22+
it('does not call shuffle method', () => {
23+
expect(shuffle).toHaveBeenCalledTimes(1);
24+
});
2025
});
2126

22-
it('returns "#388E3C" on the twenty first time', () => {
23-
times(getRandomColor, COLORS.length - 2);
24-
expect(getRandomColor()).toBe('#388E3C');
27+
describe('When getting the 23˚ color', () => {
28+
beforeEach(() => {
29+
times(getRandomColor, 21);
30+
});
31+
32+
it('calls shuffle method', () => {
33+
expect(shuffle).toHaveBeenCalledTimes(2);
34+
});
2535
});
2636
});
2737
});

0 commit comments

Comments
 (0)