1+ import { describe , expect , it } from '@jest/globals' ;
12const ValidationError = require ( './ValidationError' ) ;
23const MESSAGES = require ( './constants/messages' ) ;
34
4- describe ( 'The validation error' , ( ) => {
5-
5+ describe ( 'the validation error' , ( ) => {
66 describe ( 'constructor' , ( ) => {
7-
87 it ( 'should throw when not passing data' , ( ) => {
98 expect ( ( ) => new ValidationError ( ) )
109 . toThrow ( new Error ( 'Missing data.' ) ) ;
1110 } ) ;
1211
1312 it ( 'should throw when not passing a line' , ( ) => {
1413 const data = { } ;
14+
1515 expect ( ( ) => new ValidationError ( data ) )
1616 . toThrow ( new Error ( 'Missing linenumber in data.' ) ) ;
1717 } ) ;
@@ -20,6 +20,7 @@ describe('The validation error', () => {
2020 const data = {
2121 line : 42 ,
2222 } ;
23+
2324 expect ( ( ) => new ValidationError ( data ) )
2425 . toThrow ( new Error ( 'Missing errorcode in data.' ) ) ;
2526 } ) ;
@@ -29,6 +30,7 @@ describe('The validation error', () => {
2930 line : 42 ,
3031 code : MESSAGES . INDENTATION_TABS . code ,
3132 } ;
33+
3234 expect ( ( ) => new ValidationError ( data ) )
3335 . toThrow ( new Error ( 'Missing errortype in data.' ) ) ;
3436 } ) ;
@@ -39,6 +41,7 @@ describe('The validation error', () => {
3941 code : MESSAGES . INDENTATION_TABS . code ,
4042 type : MESSAGES . INDENTATION_TABS . type ,
4143 } ;
44+
4245 expect ( ( ) => new ValidationError ( data ) )
4346 . toThrow ( new Error ( 'Missing errormessage in data.' ) ) ;
4447 } ) ;
@@ -51,6 +54,7 @@ describe('The validation error', () => {
5154 message : MESSAGES . INDENTATION_TABS . message ,
5255 } ;
5356 const error = new ValidationError ( data ) ;
57+
5458 expect ( error ) . toEqual ( expect . objectContaining ( {
5559 line : 42 ,
5660 code : MESSAGES . INDENTATION_TABS . code ,
@@ -70,12 +74,13 @@ describe('The validation error', () => {
7074 foo : true ,
7175 } ;
7276 const error = new ValidationError ( data , payload ) ;
77+
7378 expect ( error ) . toEqual ( expect . objectContaining ( {
7479 line : 42 ,
7580 code : MESSAGES . INDENTATION_TABS . code ,
7681 type : MESSAGES . INDENTATION_TABS . type ,
7782 message : MESSAGES . INDENTATION_TABS . message ,
78- payload : payload ,
83+ payload,
7984 } ) ) ;
8085 expect ( error . payload ) . not . toBe ( payload ) ;
8186 expect ( error . payload ) . toEqual ( payload ) ;
@@ -88,7 +93,8 @@ describe('The validation error', () => {
8893 type : MESSAGES . INDENTATION_TABS . type ,
8994 message : MESSAGES . INDENTATION_TABS . message ,
9095 } ;
91- const payload = 'This is a payload'
96+ const payload = 'This is a payload' ;
97+
9298 expect ( ( ) => new ValidationError ( data , payload ) )
9399 . toThrow ( new Error ( 'The payload must be an object.' ) ) ;
94100 } ) ;
@@ -101,10 +107,9 @@ describe('The validation error', () => {
101107 message : MESSAGES . INDENTATION_TABS . message ,
102108 } ;
103109 const payload = [ 'This is a payload' ] ;
110+
104111 expect ( ( ) => new ValidationError ( data , payload ) )
105112 . toThrow ( new Error ( 'The payload must be an object.' ) ) ;
106113 } ) ;
107-
108114 } ) ;
109-
110115} ) ;
0 commit comments