55 */
66
77const { Assert : BaseAssert , Violation } = require ( 'validator.js' ) ;
8+ const { describe, it } = require ( 'node:test' ) ;
89const BigNumber = require ( 'bignumber.js' ) ;
9- const BigNumberEqualToAssert = require ( '../../src/asserts/big-number-equal-to-assert' ) ;
10+ const BigNumberEqualToAssert = require ( '../../src/asserts/big-number-equal-to-assert.js ' ) ;
1011
1112/**
1213 * Extend `Assert` with `BigNumberEqualToAssert`.
@@ -21,102 +22,108 @@ const Assert = BaseAssert.extend({
2122 */
2223
2324describe ( 'BigNumberEqualToAssert' , ( ) => {
24- it ( 'should throw an error if `value` is missing' , ( ) => {
25+ it ( 'should throw an error if `value` is missing' , ( { assert } ) => {
2526 try {
2627 Assert . bigNumberEqualTo ( ) ;
2728
28- fail ( ) ;
29+ assert . fail ( ) ;
2930 } catch ( e ) {
30- expect ( e . message ) . toBe ( 'A value is required.' ) ;
31+ assert . equal ( e . message , 'A value is required.' ) ;
3132 }
3233 } ) ;
3334
3435 [ undefined , { validateSignificantDigits : true } , { validateSignificantDigits : false } ] . forEach ( option => {
3536 describe ( `with option '${
3637 option ? `{ validateSignificantDigits: ${ option . validateSignificantDigits } }` : undefined
3738 } '`, ( ) => {
38- it ( 'should throw an error if `value` is not a number' , ( ) => {
39+ it ( 'should throw an error if `value` is not a number' , ( { assert } ) => {
3940 try {
4041 Assert . bigNumberEqualTo ( { } , option ) ;
4142
42- fail ( ) ;
43+ assert . fail ( ) ;
4344 } catch ( e ) {
44- expect ( e ) . toBeInstanceOf ( Violation ) ;
45- expect ( e . show ( ) . violation . message ) . toMatch ( / N o t a n u m b e r / ) ;
45+ assert . ok ( e instanceof Violation ) ;
46+ assert . ok ( e . show ( ) . violation . message . match ( / N o t a n u m b e r / ) ) ;
4647 }
4748 } ) ;
4849
49- it ( 'should throw an error if the input value is not a number' , ( ) => {
50+ it ( 'should throw an error if the input value is not a number' , ( { assert } ) => {
5051 const choices = [ [ ] , { } , '' ] ;
5152
5253 choices . forEach ( choice => {
5354 try {
5455 Assert . bigNumberEqualTo ( 10 , option ) . validate ( choice ) ;
5556
56- fail ( ) ;
57+ assert . fail ( ) ;
5758 } catch ( e ) {
58- expect ( e ) . toBeInstanceOf ( Violation ) ;
59+ assert . ok ( e instanceof Violation ) ;
5960 }
6061 } ) ;
6162 } ) ;
6263
63- it ( 'should throw an error if the input number is greater than the value' , ( ) => {
64+ it ( 'should throw an error if the input number is greater than the value' , ( { assert } ) => {
6465 try {
6566 Assert . bigNumberEqualTo ( 10 , option ) . validate ( 12 ) ;
6667
67- fail ( ) ;
68+ assert . fail ( ) ;
6869 } catch ( e ) {
69- expect ( e ) . toBeInstanceOf ( Violation ) ;
70+ assert . ok ( e instanceof Violation ) ;
7071 }
7172 } ) ;
7273
73- it ( 'should throw an error if the input number is less than the value' , ( ) => {
74+ it ( 'should throw an error if the input number is less than the value' , ( { assert } ) => {
7475 try {
7576 Assert . bigNumberEqualTo ( 10 , option ) . validate ( 9 ) ;
7677
77- fail ( ) ;
78+ assert . fail ( ) ;
7879 } catch ( e ) {
79- expect ( e ) . toBeInstanceOf ( Violation ) ;
80+ assert . ok ( e instanceof Violation ) ;
8081 }
8182 } ) ;
8283
83- it ( 'should expose `assert` equal to `BigNumberEqualTo`' , ( ) => {
84+ it ( 'should expose `assert` equal to `BigNumberEqualTo`' , ( { assert } ) => {
8485 try {
8586 Assert . bigNumberEqualTo ( 1 , option ) . validate ( 0.1 ) ;
8687
87- fail ( ) ;
88+ assert . fail ( ) ;
8889 } catch ( e ) {
89- expect ( e . show ( ) . assert ) . toBe ( 'BigNumberEqualTo' ) ;
90+ assert . equal ( e . show ( ) . assert , 'BigNumberEqualTo' ) ;
9091 }
9192 } ) ;
9293
93- it ( 'should expose `assert` equal to `BigNumberEqualTo` and `message` on the violation if the input value is not a number' , ( ) => {
94+ it ( 'should expose `assert` equal to `BigNumberEqualTo` and `message` on the violation if the input value is not a number' , ( {
95+ assert
96+ } ) => {
9497 try {
9598 Assert . bigNumberEqualTo ( 10 , option ) . validate ( { } ) ;
9699
97- fail ( ) ;
100+ assert . fail ( ) ;
98101 } catch ( e ) {
99- expect ( e . show ( ) . assert ) . toBe ( 'BigNumberEqualTo' ) ;
100- expect ( e . show ( ) . violation . message ) . toMatch ( / N o t a n u m b e r / ) ;
102+ assert . equal ( e . show ( ) . assert , 'BigNumberEqualTo' ) ;
103+ assert . ok ( e . show ( ) . violation . message . match ( / N o t a n u m b e r / ) ) ;
101104 }
102105 } ) ;
103106
104- it ( 'should expose `value` on the violation' , ( ) => {
107+ it ( 'should expose `value` on the violation' , ( { assert } ) => {
105108 try {
106109 Assert . bigNumberEqualTo ( 10 , option ) . validate ( 0.1 ) ;
107110
108- fail ( ) ;
111+ assert . fail ( ) ;
109112 } catch ( e ) {
110- expect ( e . show ( ) . violation . value ) . toBe ( '10' ) ;
113+ assert . equal ( e . show ( ) . violation . value , '10' ) ;
111114 }
112115 } ) ;
113116
114- it ( 'should accept a big number as a value' , ( ) => {
115- Assert . bigNumberEqualTo ( new BigNumber ( 10 ) , option ) . validate ( 10 ) ;
117+ it ( 'should accept a big number as a value' , ( { assert } ) => {
118+ assert . doesNotThrow ( ( ) => {
119+ Assert . bigNumberEqualTo ( new BigNumber ( 10 ) , option ) . validate ( 10 ) ;
120+ } ) ;
116121 } ) ;
117122
118- it ( 'should accept a number that is equal to value' , ( ) => {
119- Assert . bigNumberEqualTo ( 10 , option ) . validate ( 10 ) ;
123+ it ( 'should accept a number that is equal to value' , ( { assert } ) => {
124+ assert . doesNotThrow ( ( ) => {
125+ Assert . bigNumberEqualTo ( 10 , option ) . validate ( 10 ) ;
126+ } ) ;
120127 } ) ;
121128 } ) ;
122129 } ) ;
0 commit comments