Download wp-calypso/client/lib/make-json-schema-parser/test/index.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.79 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/lib/make-json-schema-parser/test/index.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/lib/make-json-schema-parser/test/index.js
-
curl -L -o index.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/lib/make-json-schema-parser/test/index.js
1.79 kB
| import makeJsonSchemaParser from '..'; | |
| describe( 'makeJsonSchemaParser', () => { | |
| test( 'should return a function', () => { | |
| expect( () => makeJsonSchemaParser( {} )() ).not.toThrow(); | |
| } ); | |
| test( 'should throw SchemaError on if data does not validate', () => { | |
| const parser = makeJsonSchemaParser( { type: 'null' } ); | |
| expect( () => parser( 0 ) ).toThrow( Error, 'Failed to validate with JSON schema' ); | |
| } ); | |
| test( 'should throw TransformerError if error occurs during transformation', () => { | |
| const transformer = () => { | |
| throw Error( 'Testing error during transform' ); | |
| }; | |
| const parser = makeJsonSchemaParser( {}, transformer ); | |
| expect( () => parser( 0 ) ).toThrow( Error, 'Testing error during transform' ); | |
| } ); | |
| test( 'should return input unchanged if valid and no transformer supplied', () => { | |
| const parser = makeJsonSchemaParser( { type: 'integer' } ); | |
| expect( parser( 0 ) ).toBe( 0 ); | |
| } ); | |
| test( 'should return the result of transformation', () => { | |
| const transformer = ( a ) => a + 1; | |
| const parser = makeJsonSchemaParser( { type: 'integer' }, transformer ); | |
| expect( parser( 0 ) ).toBe( 1 ); | |
| } ); | |
| test( 'should validate with additional fields', () => { | |
| const schema = { | |
| type: 'object', | |
| properties: { | |
| include: { type: 'string' }, | |
| }, | |
| }; | |
| const parser = makeJsonSchemaParser( schema ); | |
| expect( () => | |
| parser( { | |
| include: 'include', | |
| exclude: 'exclude', | |
| } ) | |
| ).not.toThrow(); | |
| } ); | |
| test( 'should filter additional fields', () => { | |
| const schema = { | |
| type: 'object', | |
| properties: { | |
| include: { type: 'string' }, | |
| }, | |
| }; | |
| const parser = makeJsonSchemaParser( schema ); | |
| expect( | |
| parser( { | |
| include: 'include', | |
| exclude: 'exclude', | |
| } ) | |
| ).toEqual( { include: 'include' } ); | |
| } ); | |
| } ); | |