FCF 2.0 development in progress...
> > > > > >
[News] [Packages API] [Downloads] [Donate to the project] [Contacts]

compare() method from fcf.NUnitest.Unitest class

compare(string a_operation, mixed a_left, mixed a_right, boolean a_strict = false)

Package: fcf-framework-unitest

File: fcf-framework-unitest:unitest.js

Available from version: 1.0.1

Compares two values using the given comparison operation a_operation, and if the comparison returns false, then raises a test error.

Arguments

string a_operation
- comparison operation. Can take one of the following values:

  • "=" | "==" - Equality comparison operation

  • "!=" - Comparison operation for inequality

  • "<" - Less than comparison operation

  • "<=" - Comparison operation for less than or equal to

  • ">" - Compare operation for more

  • ">=" - Compare operation for greater than or equal to

mixed a_left
- First comparison value

mixed a_right
- Second comparison value

boolean a_strict = false
- If the argument is false, then strict comparison is used for the "==" and "!=" operations ("===" )

Example: Function application

let fcf = require("fcf-framework-core"); let unitest = require("fcf-framework-unitest"); fcf.test("Some test", (a_unitest)=>{ a_unitest.compare("==", 1, 2); }); unitest.run() .finally(()=>{ process.exit(0); });

Output:

2023-05-10 03:02:53.296 [PID:144669] [LOG] [MOD:UniTest]: ==================================================== 2023-05-10 03:02:53.300 [PID:144669] [LOG] [MOD:UniTest]: Start testing on the server side... 2023-05-10 03:02:53.301 [PID:144669] [LOG] [MOD:UniTest]: Parts: * 2023-05-10 03:02:53.301 [PID:144669] [LOG] [MOD:UniTest]: Groups: * 2023-05-10 03:02:53.302 [PID:144669] [LOG] [MOD:UniTest]: Tests: * 2023-05-10 03:02:53.303 [PID:144669] [LOG] [MOD:UniTest]: 2023-05-10 03:02:53.303 [PID:144669] [LOG] [MOD:UniTest]: Start local tests... 2023-05-10 03:02:53.303 [PID:144669] [LOG] [MOD:UniTest]: -------------------- 2023-05-10 03:02:53.303 [PID:144669] [LOG] [MOD:UniTest]: Test [default][default][Some test] running ... 2023-05-10 03:02:53.308 [PID:144669] [LOG] [MOD:UniTest]: Test [default][default][Some test] is failed. Position: /home/user/project/index.js:9 Error: "1" and "2" are not equal Stack: Namespace.Unitest.compare (/home/user/project/node_modules/fcf-framework-unitest/unitest.js:205:19) Object.test (/home/user/project/index.js:9:13) Actions. (/home/user/project/node_modules/fcf-framework-unitest/unitest.js:612:26) Actions._execute (/home/user/project/node_modules/fcf-framework-core/fcf.js:3149:24) Actions.then (/home/user/project/node_modules/fcf-framework-core/fcf.js:2595:16) Namespace.Unitest._runLocalTests (/home/user/project/node_modules/fcf-framework-unitest/unitest.js:608:14) Actions. (/home/user/project/node_modules/fcf-framework-unitest/unitest.js:529:25) Actions._execute (/home/user/project/node_modules/fcf-framework-core/fcf.js:3154:24) Object.complete (/home/user/project/node_modules/fcf-framework-core/fcf.js:3113:18) (/home/user/project/node_modules/fcf-framework-core/fcf.js:3168:17) 2023-05-10 03:02:53.309 [PID:144669] [LOG] [MOD:UniTest]: 2023-05-10 03:02:53.309 [PID:144669] [LOG] [MOD:UniTest]: ---------------------------------------------------- 2023-05-10 03:02:53.310 [PID:144669] [LOG] [MOD:UniTest]: 1 test have been completed. 2023-05-10 03:02:53.310 [PID:144669] [LOG] [MOD:UniTest]: Errors: 1; Successfully: 0; Total: 1 2023-05-10 03:02:53.310 [PID:144669] [LOG] [MOD:UniTest]: Tests that failed: Executor server: [default][default][Some test]