File tree Expand file tree Collapse file tree 2 files changed +47
-1
lines changed
Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -86,7 +86,7 @@ function oneVerifyer(tester, tests) {
8686
8787function createOneReaderWriter ( verify , tests , method ) {
8888 return ( value , options = { } , base = undefined ) => {
89- verify ( value ) ;
89+ verify ( value , options ) ;
9090 for ( const test of tests ) {
9191 const readOrWrite = test . verify [ method ] ;
9292 if ( readOrWrite ) {
Original file line number Diff line number Diff line change @@ -218,6 +218,52 @@ describe('one', () => {
218218 ) ;
219219 } ) ;
220220
221+ it ( 'fails with given error code for reader' , ( ) => {
222+ const oneSchema = schema ( one ( literal ( null ) , object ( { bar : integer } ) ) ) ;
223+
224+ assert . exception (
225+ ( ) => {
226+ // @ts -expect-error
227+ oneSchema . read ( { foo : true } , { error_code : 'INVALID' } ) ;
228+ } ,
229+ {
230+ code : 'INVALID'
231+ }
232+ ) ;
233+ } ) ;
234+
235+ it ( 'fails with error code from schema' , ( ) => {
236+ const oneSchema = schema ( one ( literal ( null ) , object ( { bar : integer } ) ) , {
237+ error_code : 'INVALID'
238+ } ) ;
239+
240+ assert . exception (
241+ ( ) => {
242+ // @ts -expect-error
243+ oneSchema ( { foo : true } ) ;
244+ } ,
245+ {
246+ code : 'INVALID'
247+ }
248+ ) ;
249+ } ) ;
250+
251+ it . skip ( 'fails with error code from schema for reader' , ( ) => {
252+ const oneSchema = schema ( one ( literal ( null ) , object ( { bar : integer } ) ) , {
253+ error_code : 'INVALID'
254+ } ) ;
255+
256+ assert . exception (
257+ ( ) => {
258+ // @ts -expect-error
259+ oneSchema . read ( { foo : true } ) ;
260+ } ,
261+ {
262+ code : 'INVALID'
263+ }
264+ ) ;
265+ } ) ;
266+
221267 it ( 'passes validator' , ( ) => {
222268 const oneSchema = schema ( one ( literal ( null ) , object ( { bar : integer } ) ) ) ;
223269
You can’t perform that action at this time.
0 commit comments