import { IsBufferEncodingConstraint } from './is-buffer-encoding.validator' ; describe ( 'IsBufferEncoding' , ( ) => { const bufferIsEncodingMock = jest . spyOn ( Buffer , 'isEncoding' ) ; let validator ; beforeEach ( ( ) => { validator = new IsBufferEncodingConstraint ( ) ; jest . resetAllMocks ( ) ; } ) ; describe ( 'validate' , ( ) => { it ( 'should call Buffer.isEncoding' , ( ) => { const input = 'foo' ; validator . validate ( input ) ; expect ( bufferIsEncodingMock ) . toHaveBeenCalledTimes ( 1 ) ; expect ( bufferIsEncodingMock ) . toHaveBeenCalledWith ( input ) ; } ) ; it ( 'should return truthy result from Buffer.isEncoding' , ( ) => { const input = 'foo' ; bufferIsEncodingMock . mockReturnValue ( true ) ; const result = validator . validate ( input ) ; expect ( result ) . toBeTruthy ( ) ; } ) ; it ( 'should return falsy result from Buffer.isEncoding' , ( ) => { const input = 'foo' ; bufferIsEncodingMock . mockReturnValue ( false ) ; const result = validator . validate ( input ) ; expect ( result ) . toBeFalsy ( ) ; } ) ; it ( 'should return false if not a string' , ( ) => { const input = { foo : [ ] } ; const result = validator . validate ( input ) ; expect ( result ) . toBeFalsy ( ) ; } ) ; } ) ; } ) ;