11import { test , suite , assert } from '../x-test.js' ;
22
3- for ( const [ label , fn ] of [
3+ for ( const [ name , fn ] of [
44 [ 'test' , test ] ,
55 [ 'test.skip' , test . skip ] ,
66 [ 'test.only' , test . only ] ,
77 [ 'test.todo' , test . todo ] ,
88] ) {
9- suite ( label , ( ) => {
10- test ( 'accepts valid arguments ' , ( ) => {
9+ suite ( name , ( ) => {
10+ test ( 'accepts (name, fn) ' , ( ) => {
1111 fn ( 'valid test' , ( ) => { } ) ;
1212 } ) ;
1313
14- test ( 'accepts valid arguments with timeout' , ( ) => {
15- fn ( 'valid test with timeout' , ( ) => { } , 1000 ) ;
14+ test ( 'accepts (name, options, fn)' , ( ) => {
15+ fn ( 'valid test with options' , { timeout : 1000 } , ( ) => { } ) ;
16+ fn ( 'valid test with empty options' , { } , ( ) => { } ) ;
1617 } ) ;
1718
1819 test ( 'throws with too few arguments' , ( ) => {
@@ -22,26 +23,30 @@ for (const [label, fn] of [
2223
2324 test ( 'throws if name is not a string' , ( ) => {
2425 assert . throws ( ( ) => fn ( 42 , ( ) => { } ) , / ^ E r r o r : u n e x p e c t e d n a m e , e x p e c t e d s t r i n g b u t g o t " 4 2 " $ / ) ;
26+ assert . throws ( ( ) => fn ( 42 , { } , ( ) => { } ) , / ^ E r r o r : u n e x p e c t e d n a m e , e x p e c t e d s t r i n g b u t g o t " 4 2 " $ / ) ;
2527 } ) ;
2628
2729 test ( 'throws if fn is not a Function' , ( ) => {
2830 assert . throws ( ( ) => fn ( 'name' , 'not-a-function' ) , / ^ E r r o r : u n e x p e c t e d f n , e x p e c t e d F u n c t i o n b u t g o t " n o t - a - f u n c t i o n " $ / ) ;
31+ assert . throws ( ( ) => fn ( 'name' , { } , 'not-a-function' ) , / ^ E r r o r : u n e x p e c t e d f n , e x p e c t e d F u n c t i o n b u t g o t " n o t - a - f u n c t i o n " $ / ) ;
2932 } ) ;
3033
31- test ( 'throws if name is not a string with timeout' , ( ) => {
32- assert . throws ( ( ) => fn ( 42 , ( ) => { } , 1000 ) , / ^ E r r o r : u n e x p e c t e d n a m e , e x p e c t e d s t r i n g b u t g o t " 4 2 " $ / ) ;
34+ test ( 'throws if options is not a plain object' , ( ) => {
35+ assert . throws ( ( ) => fn ( 'name' , null , ( ) => { } ) , / ^ E r r o r : u n e x p e c t e d o p t i o n s , e x p e c t e d o b j e c t b u t g o t " n u l l " $ / ) ;
36+ assert . throws ( ( ) => fn ( 'name' , 42 , ( ) => { } ) , / ^ E r r o r : u n e x p e c t e d o p t i o n s , e x p e c t e d o b j e c t b u t g o t " 4 2 " $ / ) ;
37+ assert . throws ( ( ) => fn ( 'name' , [ ] , ( ) => { } ) , / ^ E r r o r : u n e x p e c t e d o p t i o n s , e x p e c t e d o b j e c t b u t g o t " " $ / ) ;
3338 } ) ;
3439
35- test ( 'throws if fn is not a Function with timeout ' , ( ) => {
36- assert . throws ( ( ) => fn ( 'name' , 'not-a-function' , 1000 ) , / ^ E r r o r : u n e x p e c t e d f n , e x p e c t e d F u n c t i o n b u t g o t " n o t - a - f u n c t i o n " $ / ) ;
40+ test ( 'throws if options has unexpected keys ' , ( ) => {
41+ assert . throws ( ( ) => fn ( 'name' , { unknown : true } , ( ) => { } ) , / ^ E r r o r : u n e x p e c t e d o p t i o n s k e y " u n k n o w n " $ / ) ;
3742 } ) ;
3843
39- test ( 'throws if timeout is not a number' , ( ) => {
40- assert . throws ( ( ) => fn ( 'name' , ( ) => { } , 'not-a-number' ) , / ^ E r r o r : u n e x p e c t e d t i m e o u t , e x p e c t e d n u m b e r b u t g o t " n o t - a - n u m b e r " $ / ) ;
44+ test ( 'throws if options. timeout is not a number' , ( ) => {
45+ assert . throws ( ( ) => fn ( 'name' , { timeout : 'bad' } , ( ) => { } ) , / ^ E r r o r : u n e x p e c t e d o p t i o n s \. t i m e o u t , e x p e c t e d n u m b e r b u t g o t " b a d " $ / ) ;
4146 } ) ;
4247
4348 test ( 'throws on extra arguments' , ( ) => {
44- assert . throws ( ( ) => fn ( 'name' , ( ) => { } , 1000 , 'extra' ) , / ^ E r r o r : u n e x p e c t e d e x t r a a r g u m e n t s $ / ) ;
49+ assert . throws ( ( ) => fn ( 'name' , { } , ( ) => { } , 'extra' ) , / ^ E r r o r : u n e x p e c t e d e x t r a a r g u m e n t s $ / ) ;
4550 } ) ;
4651 } ) ;
4752}
0 commit comments