File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ /*
3+
4+ Write a function expect that helps developers test their code.
5+ It should take in any value val and return an object with the following two functions.
6+
7+ toBe(val) accepts another value and returns true if the two values === each other.
8+ If they are not equal, it should throw an error "Not Equal".
9+
10+
11+ notToBe(val) accepts another value and returns true if the two values !== each other.
12+ If they are equal, it should throw an error "Equal".
13+
14+
15+ Example 1:
16+
17+ Input: func = () => expect(5).toBe(5)
18+ Output: {"value": true}
19+ Explana
20+ */
21+
22+
23+ var expect = function ( val ) {
24+
25+ // return an object
26+ return {
27+ //first funtion
28+ toBe : ( value ) => {
29+
30+ if ( value === val ) {
31+ return true
32+ } else {
33+
34+ throw "Not Equal"
35+ }
36+ } ,
37+
38+ //second funtion
39+ notToBe : ( value ) => {
40+ if ( value !== val ) {
41+ return true
42+ } else {
43+ throw "Equal"
44+ }
45+
46+ }
47+
48+ }
49+ } ;
50+
51+ console . log ( expect ( 5 ) . toBe ( 5 ) ) ; // true
52+ expect ( 5 ) . toBe ( 10 ) ; // throws "Not Equal"
You can’t perform that action at this time.
0 commit comments