@@ -13,6 +13,7 @@ import {
1313 getLabelPrinter ,
1414 pluralize ,
1515 stringify ,
16+ MatcherHintOptions ,
1617} from '../' ;
1718
1819describe ( '.stringify()' , ( ) => {
@@ -98,19 +99,90 @@ describe('.ensureNumbers()', () => {
9899 } ) . not . toThrow ( ) ;
99100 } ) ;
100101
101- test ( 'throws error when expected is not a number' , ( ) => {
102+ test ( 'throws error when expected is not a number (backward compatibility) ' , ( ) => {
102103 expect ( ( ) => {
103104 // @ts -ignore
104- ensureNumbers ( 1 , 'not_a_number' ) ;
105+ ensureNumbers ( 1 , 'not_a_number' , '.toBeCloseTo' ) ;
105106 } ) . toThrowErrorMatchingSnapshot ( ) ;
106107 } ) ;
107108
108- test ( 'throws error when received is not a number' , ( ) => {
109+ test ( 'throws error when received is not a number (backward compatibility) ' , ( ) => {
109110 expect ( ( ) => {
110111 // @ts -ignore
111- ensureNumbers ( 'not_a_number' , 3 ) ;
112+ ensureNumbers ( 'not_a_number' , 3 , '.toBeCloseTo' ) ;
112113 } ) . toThrowErrorMatchingSnapshot ( ) ;
113114 } ) ;
115+
116+ describe ( 'with options' , ( ) => {
117+ const matcherName = 'toBeCloseTo' ;
118+
119+ test ( 'promise empty isNot false received' , ( ) => {
120+ const options : MatcherHintOptions = {
121+ isNot : false ,
122+ promise : '' ,
123+ secondArgument : 'precision' ,
124+ } ;
125+ expect ( ( ) => {
126+ // @ts -ignore
127+ ensureNumbers ( '' , 0 , matcherName , options ) ;
128+ } ) . toThrowErrorMatchingSnapshot ( ) ;
129+ } ) ;
130+
131+ test ( 'promise empty isNot true expected' , ( ) => {
132+ const options : MatcherHintOptions = {
133+ isNot : true ,
134+ // promise undefined is equivalent to empty string
135+ } ;
136+ expect ( ( ) => {
137+ // @ts -ignore
138+ ensureNumbers ( 0.1 , undefined , matcherName , options ) ;
139+ } ) . toThrowErrorMatchingSnapshot ( ) ;
140+ } ) ;
141+
142+ test ( 'promise rejects isNot false expected' , ( ) => {
143+ const options : MatcherHintOptions = {
144+ isNot : false ,
145+ promise : 'rejects' ,
146+ } ;
147+ expect ( ( ) => {
148+ // @ts -ignore
149+ ensureNumbers ( 0.01 , '0' , matcherName , options ) ;
150+ } ) . toThrowErrorMatchingSnapshot ( ) ;
151+ } ) ;
152+
153+ test ( 'promise rejects isNot true received' , ( ) => {
154+ const options : MatcherHintOptions = {
155+ isNot : true ,
156+ promise : 'rejects' ,
157+ } ;
158+ expect ( ( ) => {
159+ // @ts -ignore
160+ ensureNumbers ( Symbol ( '0.1' ) , 0 , matcherName , options ) ;
161+ } ) . toThrowErrorMatchingSnapshot ( ) ;
162+ } ) ;
163+
164+ test ( 'promise resolves isNot false received' , ( ) => {
165+ const options : MatcherHintOptions = {
166+ isNot : false ,
167+ promise : 'resolves' ,
168+ } ;
169+ expect ( ( ) => {
170+ // @ts -ignore
171+ ensureNumbers ( false , 0 , matcherName , options ) ;
172+ } ) . toThrowErrorMatchingSnapshot ( ) ;
173+ } ) ;
174+
175+ test ( 'promise resolves isNot true expected' , ( ) => {
176+ const options : MatcherHintOptions = {
177+ isNot : true ,
178+ promise : 'resolves' ,
179+ } ;
180+ expect ( ( ) => {
181+ // @ts -ignore
182+ ensureNumbers ( 0.1 , null , matcherName , options ) ;
183+ } ) . toThrowErrorMatchingSnapshot ( ) ;
184+ } ) ;
185+ } ) ;
114186} ) ;
115187
116188describe ( '.ensureNoExpected()' , ( ) => {
0 commit comments