-
Notifications
You must be signed in to change notification settings - Fork 0
/
strings.test.js
64 lines (47 loc) · 1.8 KB
/
strings.test.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
55
56
57
58
59
60
61
62
63
64
/**
* ************************ CHAPTER 5 ************************************************
* Strings
* ************************************************************************************
*
*
* @see https://jestjs.io/docs/en/api#testname-fn-timeout
* @author Abhijeet Bhagat
*
* NOTE :- if you need to run tests only in this test suite then use following command
* ****************************** COMMAND ********************************************
* ___________________________________________________________________________________|
* npm test -t strings.test.js |
* ___________________________________________________________________________________|
*/
/**
* use the toMatch matcher for testing the string matches.
* toMatch uses REGULAR EXPRESSIONS
*/
test('if "UC Berkeley" contains "Berk"', () => {
expect("UC Berkeley").toMatch(/Berk/);
});
// A bit complex example.
/**
* IF YOU WANT TO LEARN MORE ABOUT REGEX
* @see https://www.regular-expressions.info/
*/
test('if .com email address is in valid form i.e string@xxx.com', () => {
expect("abhi@testing.com").toMatch(/[a-zA-z0-9]+@[a-zA-z0-9]+\.com/);
});
//Exact match
test('string exact match', () => {
//using toBe
expect("abhi@testing.com").toBe("abhi@testing.com");
//using toEqual
expect("abhi@testing.com").toEqual("abhi@testing.com");
});
/**
******************************** Quiz ***************************************************
* 1. What are regular expressions
*
*/
/**
* next go to
* @see https://github.com/bhagatabhijeet/jestSamples/blob/master/arraysandobjects.test.js
* @see arraysandobjects.test.js
*/