import 'jest-extended' ; import { parseJSON } from '../src/json' ; describe ( 'Utils' , ( ) => { describe ( 'parseJSON' , ( ) => { it ( 'should handle a json encoded Buffer' , ( ) => { const input = Buffer . from ( JSON . stringify ( { foo : 'bar' } ) ) ; expect ( parseJSON ( input ) ) . toEqual ( { foo : 'bar' } ) ; } ) ; xit ( 'should handle a json base64 encoded Buffer' , ( ) => { const input = Buffer . from ( JSON . stringify ( { foo : 'bar' } ) , 'base64' ) ; expect ( parseJSON ( input ) ) . toEqual ( { foo : 'bar' } ) ; } ) ; it ( 'should handle a json encoded string' , ( ) => { const input = JSON . stringify ( { foo : 'bar' } ) ; expect ( parseJSON ( input ) ) . toEqual ( { foo : 'bar' } ) ; } ) ; it ( 'should throw a TypeError if given a non-buffer' , ( ) => { expect ( ( ) => { parseJSON ( 123 ) ; } ) . toThrowError ( 'Failure to serialize non-buffer, got "Number"' ) ; } ) ; it ( 'should throw an Error if given invalid json' , ( ) => { expect ( ( ) => { parseJSON ( Buffer . from ( 'foo:bar' ) ) ; } ) . toThrowError ( /^Failure to parse buffer, SyntaxError:/ ) ; } ) ; } ) ; } ) ;