@@ -16,6 +16,18 @@ suite('assert', () => {
1616 test ( 'uses custom message on failure' , ( ) => {
1717 assert . throws ( ( ) => assert ( false , 'custom' ) , / ^ E r r o r : c u s t o m $ / ) ;
1818 } ) ;
19+
20+ test ( 'throws if message is not a string' , ( ) => {
21+ assert . throws ( ( ) => assert ( false , 42 ) , / ^ E r r o r : u n e x p e c t e d m e s s a g e , e x p e c t e d s t r i n g b u t g o t " 4 2 " $ / ) ;
22+ } ) ;
23+
24+ test ( 'throws with no arguments' , ( ) => {
25+ assert . throws ( ( ) => assert ( ) , / ^ E r r o r : e x p e c t e d v a l u e t o a s s e r t , b u t g o t n o n e $ / ) ;
26+ } ) ;
27+
28+ test ( 'throws on extra arguments' , ( ) => {
29+ assert . throws ( ( ) => assert ( false , 'msg' , '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 $ / ) ;
30+ } ) ;
1931} ) ;
2032
2133suite ( 'assert.deepEqual' , ( ) => {
@@ -41,34 +53,91 @@ suite('assert.deepEqual', () => {
4153 const sym = Symbol ( 'x' ) ;
4254 assert . throws ( ( ) => assert . deepEqual ( { [ sym ] : 1 } , { } ) , / ^ E r r o r : d e e p E q u a l d o e s n o t s u p p o r t s y m b o l - k e y e d p r o p e r t i e s \. $ / ) ;
4355 } ) ;
56+
57+ test ( 'throws with too few arguments' , ( ) => {
58+ assert . throws ( ( ) => assert . deepEqual ( ) , / ^ E r r o r : e x p e c t e d a c t u a l a n d e x p e c t e d v a l u e s , b u t g o t t o o f e w a r g u m e n t s $ / ) ;
59+ assert . throws ( ( ) => assert . deepEqual ( 1 ) , / ^ E r r o r : e x p e c t e d a c t u a l a n d e x p e c t e d v a l u e s , b u t g o t t o o f e w a r g u m e n t s $ / ) ;
60+ } ) ;
61+
62+ test ( 'throws if message is not a string' , ( ) => {
63+ assert . throws ( ( ) => assert . deepEqual ( 1 , 2 , 42 ) , / ^ E r r o r : u n e x p e c t e d m e s s a g e , e x p e c t e d s t r i n g b u t g o t " 4 2 " $ / ) ;
64+ } ) ;
65+
66+ test ( 'throws on extra arguments' , ( ) => {
67+ assert . throws ( ( ) => assert . deepEqual ( 1 , 1 , 'msg' , '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 $ / ) ;
68+ } ) ;
4469} ) ;
4570
4671suite ( 'assert.throws' , ( ) => {
4772 test ( 'exercises the public assert.throws export' , ( ) => {
4873 assert . throws ( ( ) => { throw new Error ( 'boom' ) ; } , / b o o m / ) ;
4974 assert . throws ( ( ) => { throw new Error ( 'boom' ) ; } , / ^ E r r o r : b o o m $ / ) ;
75+ assert . throws ( ( ) => { throw new Error ( 'boom' ) ; } , / b o o m / , 'with message' ) ;
76+ } ) ;
77+
78+ test ( 'throws with too few arguments' , ( ) => {
79+ assert . throws ( ( ) => assert . throws ( ) , / ^ E r r o r : e x p e c t e d f n a n d e r r o r a r g u m e n t s , b u t g o t t o o f e w a r g u m e n t s $ / ) ;
80+ assert . throws ( ( ) => assert . throws ( ( ) => { } ) , / ^ E r r o r : e x p e c t e d f n a n d e r r o r a r g u m e n t s , b u t g o t t o o f e w a r g u m e n t s $ / ) ;
5081 } ) ;
5182
5283 test ( 'throws early if fn is not a function' , ( ) => {
53- assert . throws ( ( ) => assert . throws ( 'not a function' , / b o o m / ) , / ^ E r r o r : u n e x p e c t e d f n v a l u e " n o t a f u n c t i o n " $ / ) ;
84+ assert . throws ( ( ) => assert . throws ( 'not a function' , / b o o m / ) , / ^ 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 " $ / ) ;
5485 } ) ;
5586
5687 test ( 'throws early if error is not a RegExp' , ( ) => {
57- assert . throws ( ( ) => assert . throws ( ( ) => { } , 'not a regexp' ) , / ^ E r r o r : u n e x p e c t e d e r r o r v a l u e " n o t a r e g e x p " $ / ) ;
88+ assert . throws ( ( ) => assert . throws ( ( ) => { } , 'not a regexp' ) , / ^ E r r o r : u n e x p e c t e d e r r o r , e x p e c t e d R e g E x p b u t g o t " n o t a r e g e x p " $ / ) ;
89+ } ) ;
90+
91+ test ( 'throws early if fn is not a function with message' , ( ) => {
92+ assert . throws ( ( ) => assert . throws ( 'not a function' , / b o o m / , 'msg' ) , / ^ 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 " $ / ) ;
93+ } ) ;
94+
95+ test ( 'throws early if error is not a RegExp with message' , ( ) => {
96+ assert . throws ( ( ) => assert . throws ( ( ) => { } , 'not a regexp' , 'msg' ) , / ^ E r r o r : u n e x p e c t e d e r r o r , e x p e c t e d R e g E x p b u t g o t " n o t a r e g e x p " $ / ) ;
97+ } ) ;
98+
99+ test ( 'throws if message is not a string' , ( ) => {
100+ assert . throws ( ( ) => assert . throws ( ( ) => { throw new Error ( 'boom' ) ; } , / b o o m / , 42 ) , / ^ E r r o r : u n e x p e c t e d m e s s a g e , e x p e c t e d s t r i n g b u t g o t " 4 2 " $ / ) ;
101+ } ) ;
102+
103+ test ( 'throws on extra arguments' , ( ) => {
104+ assert . throws ( ( ) => assert . throws ( ( ) => { } , / b o o m / , 'msg' , '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 $ / ) ;
58105 } ) ;
59106} ) ;
60107
61108suite ( 'assert.rejects' , ( ) => {
62109 test ( 'exercises the public assert.rejects export' , async ( ) => {
63110 await assert . rejects ( async ( ) => { throw new Error ( 'boom' ) ; } , / b o o m / ) ;
64111 await assert . rejects ( async ( ) => { throw new Error ( 'boom' ) ; } , / ^ E r r o r : b o o m $ / ) ;
112+ await assert . rejects ( async ( ) => { throw new Error ( 'boom' ) ; } , / b o o m / , 'with message' ) ;
113+ } ) ;
114+
115+ test ( 'throws with too few arguments' , async ( ) => {
116+ await assert . rejects ( ( ) => assert . rejects ( ) , / ^ E r r o r : e x p e c t e d f n a n d e r r o r a r g u m e n t s , b u t g o t t o o f e w a r g u m e n t s $ / ) ;
117+ await assert . rejects ( ( ) => assert . rejects ( ( ) => { } ) , / ^ E r r o r : e x p e c t e d f n a n d e r r o r a r g u m e n t s , b u t g o t t o o f e w a r g u m e n t s $ / ) ;
65118 } ) ;
66119
67120 test ( 'throws early if fn is not a function' , async ( ) => {
68- await assert . rejects ( ( ) => assert . rejects ( 'not a function' , / b o o m / ) , / ^ E r r o r : u n e x p e c t e d f n v a l u e " n o t a f u n c t i o n " $ / ) ;
121+ await assert . rejects ( ( ) => assert . rejects ( 'not a function' , / b o o m / ) , / ^ 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 " $ / ) ;
69122 } ) ;
70123
71124 test ( 'throws early if error is not a RegExp' , async ( ) => {
72- await assert . rejects ( ( ) => assert . rejects ( ( ) => { } , 'not a regexp' ) , / ^ E r r o r : u n e x p e c t e d e r r o r v a l u e " n o t a r e g e x p " $ / ) ;
125+ await assert . rejects ( ( ) => assert . rejects ( ( ) => { } , 'not a regexp' ) , / ^ E r r o r : u n e x p e c t e d e r r o r , e x p e c t e d R e g E x p b u t g o t " n o t a r e g e x p " $ / ) ;
126+ } ) ;
127+
128+ test ( 'throws early if fn is not a function with message' , async ( ) => {
129+ await assert . rejects ( ( ) => assert . rejects ( 'not a function' , / b o o m / , 'msg' ) , / ^ 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 " $ / ) ;
130+ } ) ;
131+
132+ test ( 'throws early if error is not a RegExp with message' , async ( ) => {
133+ await assert . rejects ( ( ) => assert . rejects ( ( ) => { } , 'not a regexp' , 'msg' ) , / ^ E r r o r : u n e x p e c t e d e r r o r , e x p e c t e d R e g E x p b u t g o t " n o t a r e g e x p " $ / ) ;
134+ } ) ;
135+
136+ test ( 'throws if message is not a string' , async ( ) => {
137+ await assert . rejects ( ( ) => assert . rejects ( async ( ) => { throw new Error ( 'boom' ) ; } , / b o o m / , 42 ) , / ^ E r r o r : u n e x p e c t e d m e s s a g e , e x p e c t e d s t r i n g b u t g o t " 4 2 " $ / ) ;
138+ } ) ;
139+
140+ test ( 'throws on extra arguments' , async ( ) => {
141+ await assert . rejects ( ( ) => assert . rejects ( async ( ) => { } , / b o o m / , 'msg' , '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 $ / ) ;
73142 } ) ;
74143} ) ;
0 commit comments