-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.js
More file actions
79 lines (62 loc) · 1.98 KB
/
index.test.js
File metadata and controls
79 lines (62 loc) · 1.98 KB
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
76
77
78
79
//import {add, sub, mult, div} from './modules/operations.js'
import { add, sub, mult, div, isNull, checkValue } from './modules/operations'
import { Person } from './modules/Person'
import { arrayData } from './data/arrayData'
import { fetchData } from './modules/fetchData'
import { reverseString, checkPalindrome } from './modules/stringOperations'
test("Add 1 + 1 equals 2", () => {
expect(add(1, 1)).toBe(2)
})
test("Add 1 + 1 not equals 3", () => {
expect(add(1, 1)).not.toBe(3)
})
test("1 minus 1 equals 0", () =>{
expect(sub(1,1)).toBe(0)
})
test("4 divided by 2 equals 2", () =>{
expect(div(4,2)).toBe(2)
})
test("Is Null", () => {
expect(isNull()).toBeNull()
})
test("Check Value", () => {
expect(checkValue(0)).toBeFalsy()
})
test("Less than 100", () => {
expect(mult(1, 1)).toBeLessThan(100)
})
test("Check Value", () => {
const p = new Person('Ann', 'Smith')
expect(p.getPerson()).toStrictEqual({ name: 'Ann', surname: 'Smith' })
})
test('No "i" in "Jest"', () => {
expect('Jest').not.toMatch(/i/)
})
test('Lynn should be in data array', () => {
expect(arrayData).toContain("Lynn")
})
test('Get user with name "Leanne Graham"', async () => {
const url = 'https://jsonplaceholder.typicode.com/users/1'
const data = await fetchData(url)
expect(data.name).toStrictEqual("Leanne Graham")
})
test('Get with invalid URL', async () => {
const url = 'https://oneTwoThree/abc/'
const data = await fetchData(url)
expect(data).toStrictEqual('An Error Occured')
})
test('Reverse a string function is defined', () => {
expect(reverseString).toBeDefined()
})
test('Reverse a string is a function', () => {
expect(typeof reverseString).toStrictEqual('function')
})
test('Reverse a string', () => {
expect(reverseString("abc")).toStrictEqual("cba")
})
test('Reverse a string II', () => {
expect(reverseString("abc")).not.toStrictEqual("abc")
})
test('Check palindrome', () => {
expect(checkPalindrome("ANNA")).toBe(true)
})