@@ -13,26 +13,33 @@ import { type AnyAssertion } from '../../src/types.js';
1313import { expect , expectAsync } from '../custom-assertions.js' ;
1414import { takeErrorSnapshot } from './error-snapshot-util.js' ;
1515
16- const failingAssertions = new Map < AnyAssertion , ( ) => Promise < void > > ( [
17- [
18- assertions . functionFulfillWithValueSatisfyingAssertion ,
19- async ( ) => {
16+ interface TestCase {
17+ assertion : AnyAssertion ;
18+ description ?: string ;
19+ testFn : ( ) => Promise < void > ;
20+ }
21+
22+ const failingAssertions : TestCase [ ] = [
23+ {
24+ assertion : assertions . functionFulfillWithValueSatisfyingAssertion ,
25+ testFn : async ( ) => {
2026 await expectAsync (
2127 async ( ) => 'wrong' ,
2228 'to fulfill with value satisfying' ,
2329 42 ,
2430 ) ;
2531 } ,
26- ] ,
27- [
28- assertions . functionRejectAssertion ,
29- async ( ) => {
32+ } ,
33+ {
34+ assertion : assertions . functionRejectAssertion ,
35+ testFn : async ( ) => {
3036 await expectAsync ( async ( ) => 'success' , 'to reject' ) ;
3137 } ,
32- ] ,
33- [
34- assertions . functionRejectWithErrorSatisfyingAssertion ,
35- async ( ) => {
38+ } ,
39+ {
40+ assertion : assertions . functionRejectWithErrorSatisfyingAssertion ,
41+ description : 'with object parameter' ,
42+ testFn : async ( ) => {
3643 await expectAsync (
3744 async ( ) => {
3845 throw new Error ( 'wrong message' ) ;
@@ -41,10 +48,36 @@ const failingAssertions = new Map<AnyAssertion, () => Promise<void>>([
4148 { message : 'expected message' } ,
4249 ) ;
4350 } ,
44- ] ,
45- [
46- assertions . functionRejectWithTypeAssertion ,
47- async ( ) => {
51+ } ,
52+ {
53+ assertion : assertions . functionRejectWithErrorSatisfyingAssertion ,
54+ description : 'with object regex parameter' ,
55+ testFn : async ( ) => {
56+ await expectAsync (
57+ async ( ) => {
58+ throw new Error ( 'wrong message' ) ;
59+ } ,
60+ 'to reject with error satisfying' ,
61+ { message : / e x p e c t e d m e s s a g e / } ,
62+ ) ;
63+ } ,
64+ } ,
65+ {
66+ assertion : assertions . functionRejectWithErrorSatisfyingAssertion ,
67+ description : 'with regex parameter' ,
68+ testFn : async ( ) => {
69+ await expectAsync (
70+ async ( ) => {
71+ throw new Error ( 'wrong message' ) ;
72+ } ,
73+ 'to reject with error satisfying' ,
74+ / e x p e c t e d m e s s a g e / ,
75+ ) ;
76+ } ,
77+ } ,
78+ {
79+ assertion : assertions . functionRejectWithTypeAssertion ,
80+ testFn : async ( ) => {
4881 await expectAsync (
4982 async ( ) => {
5083 throw new Error ( 'error' ) ;
@@ -53,24 +86,24 @@ const failingAssertions = new Map<AnyAssertion, () => Promise<void>>([
5386 TypeError ,
5487 ) ;
5588 } ,
56- ] ,
57- [
58- assertions . functionResolveAssertion ,
59- async ( ) => {
89+ } ,
90+ {
91+ assertion : assertions . functionResolveAssertion ,
92+ testFn : async ( ) => {
6093 await expectAsync ( async ( ) => {
6194 throw new Error ( 'failure' ) ;
6295 } , 'to resolve' ) ;
6396 } ,
64- ] ,
65- [
66- assertions . promiseRejectAssertion ,
67- async ( ) => {
97+ } ,
98+ {
99+ assertion : assertions . promiseRejectAssertion ,
100+ testFn : async ( ) => {
68101 await expectAsync ( Promise . resolve ( 'success' ) , 'to reject' ) ;
69102 } ,
70- ] ,
71- [
72- assertions . promiseRejectWithErrorSatisfyingAssertion ,
73- async ( ) => {
103+ } ,
104+ {
105+ assertion : assertions . promiseRejectWithErrorSatisfyingAssertion ,
106+ testFn : async ( ) => {
74107 // Use thenable object to avoid unhandled rejection
75108 const rejectingThenable = {
76109 then ( _resolve : ( value : any ) => void , reject : ( reason : any ) => void ) {
@@ -81,10 +114,10 @@ const failingAssertions = new Map<AnyAssertion, () => Promise<void>>([
81114 message : 'expected message' ,
82115 } ) ;
83116 } ,
84- ] ,
85- [
86- assertions . promiseRejectWithTypeAssertion ,
87- async ( ) => {
117+ } ,
118+ {
119+ assertion : assertions . promiseRejectWithTypeAssertion ,
120+ testFn : async ( ) => {
88121 // Use thenable object to avoid unhandled rejection
89122 const rejectingThenable = {
90123 then ( _resolve : ( value : any ) => void , reject : ( reason : any ) => void ) {
@@ -93,10 +126,10 @@ const failingAssertions = new Map<AnyAssertion, () => Promise<void>>([
93126 } ;
94127 await expectAsync ( rejectingThenable , 'to reject with a' , TypeError ) ;
95128 } ,
96- ] ,
97- [
98- assertions . promiseResolveAssertion ,
99- async ( ) => {
129+ } ,
130+ {
131+ assertion : assertions . promiseResolveAssertion ,
132+ testFn : async ( ) => {
100133 // Use thenable object to avoid unhandled rejection
101134 const rejectingThenable = {
102135 then ( _resolve : ( value : any ) => void , reject : ( reason : any ) => void ) {
@@ -105,38 +138,46 @@ const failingAssertions = new Map<AnyAssertion, () => Promise<void>>([
105138 } ;
106139 await expectAsync ( rejectingThenable , 'to resolve' ) ;
107140 } ,
108- ] ,
109- [
110- assertions . promiseResolveWithValueSatisfyingAssertion ,
111- async ( ) => {
141+ } ,
142+ {
143+ assertion : assertions . promiseResolveWithValueSatisfyingAssertion ,
144+ testFn : async ( ) => {
112145 await expectAsync (
113146 Promise . resolve ( 'wrong' ) ,
114147 'to fulfill with value satisfying' ,
115148 42 ,
116149 ) ;
117150 } ,
118- ] ,
119- ] ) ;
151+ } ,
152+ ] ;
120153
121154describe ( 'Async Parametric Assertion Error Snapshots' , ( ) => {
122- it ( `should test all available assertions in SyncCollectionAssertions` , ( ) => {
155+ it ( `should test all available assertions in AsyncParametricAssertions` , ( ) => {
156+ // Create a Map from unique assertions in our test cases
157+ const assertionMap = new Map ( ) ;
158+ for ( const testCase of failingAssertions ) {
159+ assertionMap . set ( testCase . assertion , testCase . testFn ) ;
160+ }
161+
123162 expect (
124- failingAssertions ,
163+ assertionMap ,
125164 'to exhaustively test collection' ,
126165 'AsyncParametricAssertions' ,
127166 'from' ,
128167 AsyncParametricAssertions ,
129168 ) ;
130169 } ) ;
131170
132- for ( const assertion of Object . values ( assertions ) ) {
133- const { id } = assertion ;
134- describe ( `${ assertion } [${ id } ]` , ( ) => {
135- const failingAssertion = failingAssertions . get ( assertion ) ! ;
171+ for ( const testCase of failingAssertions ) {
172+ const { assertion, description, testFn } = testCase ;
173+ const testName = description
174+ ? `${ assertion } [${ assertion . id } ] (${ description } )`
175+ : `${ assertion } [${ assertion . id } ]` ;
136176
177+ describe ( testName , ( ) => {
137178 it (
138179 `should throw a consistent AssertionError [${ assertion . id } ] <snapshot>` ,
139- takeErrorSnapshot ( failingAssertion ) ,
180+ takeErrorSnapshot ( testFn ) ,
140181 ) ;
141182 } ) ;
142183 }
0 commit comments