33 *
44 * This source code is licensed under the MIT license found in the
55 * LICENSE file in the root directory of this source tree.
6- *
7- * @flow
86 */
97
10- import type { MatcherHintOptions } from 'types/Matchers' ;
11-
128import chalk from 'chalk' ;
139import jestDiff from 'jest-diff' ;
1410import getType from 'jest-get-type' ;
@@ -31,6 +27,14 @@ const PLUGINS = [
3127 AsymmetricMatcher ,
3228] ;
3329
30+ export type MatcherHintOptions = {
31+ comment ?: string ;
32+ isDirectExpectCall ?: boolean ;
33+ isNot ?: boolean ;
34+ promise ?: string ;
35+ secondArgument ?: string ;
36+ } ;
37+
3438export const EXPECTED_COLOR = chalk . green ;
3539export const RECEIVED_COLOR = chalk . red ;
3640const DIM_COLOR = chalk . dim ;
@@ -60,7 +64,7 @@ export const SUGGEST_TO_CONTAIN_EQUAL = chalk.dim(
6064 'Looks like you wanted to test for object/array equality with the stricter `toContain` matcher. You probably need to use `toContainEqual` instead.' ,
6165) ;
6266
63- export const stringify = ( object : any , maxDepth ? : number = 10 ) : string => {
67+ export const stringify = ( object : unknown , maxDepth : number = 10 ) : string => {
6468 const MAX_LENGTH = 10000 ;
6569 let result ;
6670
@@ -87,15 +91,15 @@ export const stringify = (object: any, maxDepth?: number = 10): string => {
8791export const highlightTrailingWhitespace = ( text : string ) : string =>
8892 text . replace ( / \s + $ / gm, chalk . inverse ( '$&' ) ) ;
8993
90- export const printReceived = ( object : any ) =>
94+ export const printReceived = ( object : unknown ) =>
9195 RECEIVED_COLOR ( highlightTrailingWhitespace ( stringify ( object ) ) ) ;
92- export const printExpected = ( value : any ) =>
96+ export const printExpected = ( value : unknown ) =>
9397 EXPECTED_COLOR ( highlightTrailingWhitespace ( stringify ( value ) ) ) ;
9498
9599export const printWithType = (
96100 name : string , // 'Expected' or 'Received'
97- value : any ,
98- print : ( value : any ) => string , // printExpected or printReceived
101+ value : unknown ,
102+ print : ( value : unknown ) => string , // printExpected or printReceived
99103) => {
100104 const type = getType ( value ) ;
101105 const hasType =
@@ -107,7 +111,7 @@ export const printWithType = (
107111} ;
108112
109113export const ensureNoExpected = (
110- expected : any ,
114+ expected : unknown ,
111115 matcherName : string ,
112116 options ?: MatcherHintOptions ,
113117) => {
@@ -126,7 +130,7 @@ export const ensureNoExpected = (
126130 }
127131} ;
128132
129- export const ensureActualIsNumber = ( actual : any , matcherName : string ) => {
133+ export const ensureActualIsNumber = ( actual : unknown , matcherName : string ) => {
130134 matcherName || ( matcherName = 'This matcher' ) ;
131135 if ( typeof actual !== 'number' ) {
132136 throw new Error (
@@ -139,7 +143,10 @@ export const ensureActualIsNumber = (actual: any, matcherName: string) => {
139143 }
140144} ;
141145
142- export const ensureExpectedIsNumber = ( expected : any , matcherName : string ) => {
146+ export const ensureExpectedIsNumber = (
147+ expected : unknown ,
148+ matcherName : string ,
149+ ) => {
143150 matcherName || ( matcherName = 'This matcher' ) ;
144151 if ( typeof expected !== 'number' ) {
145152 throw new Error (
@@ -153,8 +160,8 @@ export const ensureExpectedIsNumber = (expected: any, matcherName: string) => {
153160} ;
154161
155162export const ensureNumbers = (
156- actual : any ,
157- expected : any ,
163+ actual : unknown ,
164+ expected : unknown ,
158165 matcherName : string ,
159166) => {
160167 ensureActualIsNumber ( actual , matcherName ) ;
@@ -164,7 +171,7 @@ export const ensureNumbers = (
164171// Sometimes, e.g. when comparing two numbers, the output from jest-diff
165172// does not contain more information than the `Expected:` / `Received:` already gives.
166173// In those cases, we do not print a diff to make the output shorter and not redundant.
167- const shouldPrintDiff = ( actual : any , expected : any ) => {
174+ const shouldPrintDiff = ( actual : unknown , expected : unknown ) => {
168175 if ( typeof actual === 'number' && typeof expected === 'number' ) {
169176 return false ;
170177 }
@@ -184,7 +191,7 @@ export const pluralize = (word: string, count: number) =>
184191// return function which given each string, returns the label:
185192// string, colon, space, and enough padding spaces to align the value.
186193
187- type PrintLabel = string => string ;
194+ type PrintLabel = ( string : string ) => string ;
188195
189196export const getLabelPrinter = ( ...strings : Array < string > ) : PrintLabel => {
190197 const maxLength = strings . reduce (
0 commit comments