File tree 1 file changed +21
-0
lines changed
1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Creates an expectation object for testing values.
3
+ *
4
+ * @param {any } val - The value to be tested.
5
+ * @returns {Object } An object with two methods:
6
+ * - toBe(expected): Returns true if val === expected, otherwise throws an error "Not Equal".
7
+ * - notToBe(expected): Returns true if val !== expected, otherwise throws an error "Equal".
8
+ */
9
+ const expect = ( val ) => {
10
+ const throwError = ( message ) => { throw new Error ( message ) ; } ;
11
+ return {
12
+ toBe : ( expected ) => val === expected || throwError ( "Not Equal" ) ,
13
+ notToBe : ( expected ) => val !== expected || throwError ( "Equal" )
14
+ } ;
15
+ } ;
16
+
17
+ // Example usage:
18
+ // expect(5).toBe(5); // returns true
19
+ // expect(5).notToBe(3); // returns true
20
+ // expect(5).toBe(3); // throws "Not Equal"
21
+ // expect(5).notToBe(5); // throws "Equal"
You can’t perform that action at this time.
0 commit comments