From 1c84899f60f18ee00ac048aa7e0b38ce6d0b0235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Ooms?= Date: Mon, 15 Mar 2021 11:10:21 +0100 Subject: [PATCH] :recycle: refactor(tests): Test each error individually. --- test/src/error.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/src/error.js b/test/src/error.js index fd53c78..b0a1993 100644 --- a/test/src/error.js +++ b/test/src/error.js @@ -22,19 +22,19 @@ const errors = [ StopIteration , ] ; -function willThrow ( SpecificError ) { - return function () { throw new SpecificError(); } ; -} - -test( 'error' , t => { +const macro = (t, SpecificError) => { const r = Math.random(); const s = r.toString(); - for ( const SpecificError of errors ) { - t.truthy( new SpecificError( ) ) ; - t.is( ( new SpecificError( r ) ).message , s ) ; - t.throws( willThrow(SpecificError) , { instanceOf: SpecificError } ) ; - } + t.truthy( new SpecificError( ) ) ; + t.is( ( new SpecificError( r ) ).message , s ) ; + t.throws( () => { throw new SpecificError() ; } , { instanceOf: SpecificError } ) ; + +}; -}) ; +macro.title = (title, SpecificError) => title || (new SpecificError()).name; + +for (const error of errors) { + test(macro, error); +}