|
1 | 1 | import { times } from 'ramda'; |
2 | | -import { COLORS, getRandomColor } from './colors'; |
| 2 | +import shuffle from 'shuffle-array'; |
| 3 | +import { getRandomColor } from './colors'; |
3 | 4 |
|
4 | 5 | describe('Colors Utils', () => { |
5 | 6 | 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 | + }); |
9 | 11 |
|
10 | | - afterAll(() => { |
11 | | - Math.random.mockRestore(); |
| 12 | + it('calls shuffle method', () => { |
| 13 | + expect(shuffle).toHaveBeenCalledTimes(1); |
| 14 | + }); |
12 | 15 | }); |
13 | 16 |
|
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 | + }); |
17 | 21 |
|
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 | + }); |
20 | 25 | }); |
21 | 26 |
|
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 | + }); |
25 | 35 | }); |
26 | 36 | }); |
27 | 37 | }); |
0 commit comments