forked from cypress-io/cypress-example-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit_test_application_code_spec.js
54 lines (43 loc) · 1.38 KB
/
unit_test_application_code_spec.js
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
/// <reference types="cypress" />
import fizzbuzz from '../../fizzbuzz'
// math exports a default object with methods
import math from '../../math'
describe('Unit Test Application Code', function () {
const { add, divide, multiply, subtract } = math
before(() => {
// check if the import worked correctly
expect(add, 'add').to.be.a('function')
})
context('math.js', function () {
it('can add numbers', function () {
expect(add(1, 2)).to.eq(3)
})
it('can subtract numbers', function () {
expect(subtract(5, 12)).to.eq(-7)
})
it('can divide numbers', function () {
expect(divide(27, 9)).to.eq(3)
})
it('can muliple numbers', function () {
expect(multiply(5, 4)).to.eq(20)
})
})
context('fizzbuzz.js', function () {
function numsExpectedToEq (arr, expected) {
// loop through the array of nums and make
// sure they equal what is expected
arr.forEach((num) => {
expect(fizzbuzz(num)).to.eq(expected)
})
}
it('returns "fizz" when number is multiple of 3', function () {
numsExpectedToEq([9, 12, 18], 'fizz')
})
it('returns "buzz" when number is multiple of 5', function () {
numsExpectedToEq([10, 20, 25], 'buzz')
})
it('returns "fizzbuzz" when number is multiple of both 3 and 5', function () {
numsExpectedToEq([15, 30, 60], 'fizzbuzz')
})
})
})