@@ -15,75 +15,5 @@ limitations under the License.
15
15
*/
16
16
console . error = jest . fn ( ) ;
17
17
18
- const result = ( pass : boolean , msg : string ) => ( { pass, message : ( ) => msg } ) ;
19
- const pass = ( msg : string ) => result ( true , msg ) ;
20
- const fail = ( msg : string ) => result ( false , msg ) ;
21
-
22
- const customMatchersObj = {
23
- // The promise attribute is necessary for the type checking to work correctly
24
- // in the matchers below. It is not used in the matchers themselves as the
25
- // functions are invoked with `this` bound to the Jest matchers object.
26
- promise : undefined ,
27
-
28
- // Matcher for checking that a function throws an error of a specific type
29
- // with a specific `code` property
30
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
- toThrowWithCode ( received : any , type : any , code : string ) {
32
- const isFromReject = this && this . promise === 'rejects' ;
33
-
34
- // Must be called with either a rejected promise, or a function to be
35
- // invoked
36
- if ( ( ! received || typeof received !== 'function' ) && ! isFromReject ) {
37
- return fail ( `Excpected ${ received } to be a function` ) ;
38
- }
39
-
40
- // Type must be some kind of class (e.g. Error)
41
- if ( ! type || typeof type !== 'function' ) {
42
- return fail ( `Type argument must be a function, received ${ type } ` ) ;
43
- }
44
-
45
- if ( typeof code !== 'string' ) {
46
- return fail ( `Code argument must be a string, received ${ code } ` ) ;
47
- }
48
-
49
- // Gather the error, either from the rejected promise or by invoking the
50
- // supplied function
51
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
- let error : ( object & { code ?: string ; name ?: string } ) | null = null ;
53
- if ( isFromReject ) {
54
- error = received ;
55
- } else {
56
- try {
57
- received ( ) ;
58
- } catch ( e ) {
59
- error = e as object ;
60
- }
61
- }
62
-
63
- if ( ! error ) {
64
- return fail ( `Received function did not throw` ) ;
65
- }
66
-
67
- if ( ! ( error instanceof type ) ) {
68
- return fail (
69
- `Expected function to throw ${ type . name } , but got ${ error . name } `
70
- ) ;
71
- }
72
-
73
- if ( error . code !== code ) {
74
- return fail (
75
- `Expected error to have code "${ code } ", but got "${ error . code } "`
76
- ) ;
77
- }
78
- return pass ( `Expected function to throw ${ type . name } with code ${ code } ` ) ;
79
- } ,
80
- } ;
81
-
82
- // Strip out the dummy `promise` attribute from the custom matchers object
83
- // before passing it to Jest's `expect.extend` function
84
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
85
- const { promise : _ , ...customMatchers } = customMatchersObj ;
86
- expect . extend ( customMatchers ) ;
87
-
88
18
// Export something so we look like a an importable module
89
19
export { } ;
0 commit comments