/
fizz-buzz.spec.ts
75 lines (62 loc) · 2.45 KB
/
fizz-buzz.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import * as lib from './fizz-buzz';
describe('fizz-bizz', () => {
describe('getCountingNumbers()', () => {
it('should return an array of numbers from 0', () => {
expect(lib.getCountingNumbers(5)).toStrictEqual([0, 1, 2, 3, 4]);
});
it('should allow for starting at any specified number', () => {
expect(lib.getCountingNumbers(6, 7)).toStrictEqual([7, 8, 9, 10, 11, 12]);
});
});
describe('isDivisible()', () => {
it('should return false if NOT divisible by', () => {
expect(lib.isDivisible(1, 3)).toBe(false);
expect(lib.isDivisible(2, 3)).toBe(false);
});
it('should return true if divisible by', () => {
expect(lib.isDivisible(3, 3)).toBe(true);
});
});
describe('getFizzbuzzValue()', () => {
it('should return Fizzbuzz if divisible by 3 and 5', () => {
expect(lib.getFizzbuzzValue(30)).toBe('Fizzbuzz');
});
it('should return Fizz if divisible by 3 and NOT 5', () => {
expect(lib.getFizzbuzzValue(27)).toBe('Fizz');
});
it('should return Fizz if divisible by 5 and NOT 3', () => {
expect(lib.getFizzbuzzValue(35)).toBe('Buzz');
});
it('should return input number if NOT divisible by 5 or 3', () => {
expect(lib.getFizzbuzzValue(4)).toBe('4');
});
});
describe('getFizzbuzzValues()', () => {
beforeEach(() => {
jest.restoreAllMocks();
});
it('should use getFizzbuzzValue to create its return value', () => {
const spy = jest
.spyOn(lib, 'getFizzbuzzValue')
.mockImplementation((value: number) => { return `${value}_mock`});
expect(lib.getFizzbuzzValues([9, 35, 30, 101])).toStrictEqual([
'9_mock',
'35_mock',
'30_mock',
'101_mock',
]);
expect(spy).toHaveBeenNthCalledWith(1, 9);
expect(spy).toHaveBeenNthCalledWith(2, 35);
expect(spy).toHaveBeenNthCalledWith(3, 30);
expect(spy).toHaveBeenNthCalledWith(4, 101);
});
it('should map values of the input array to Fizzbuzz values', () => {
expect(lib.getFizzbuzzValues([9, 35, 30, 101])).toStrictEqual([
'Fizz',
'Buzz',
'Fizzbuzz',
'101',
]);
});
});
});