File size: 1,491 Bytes
1e92f2d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | /**
* @jest-environment jsdom
*/
import { renderHook } from '@testing-library/react';
import useSnakeCasedKeys from '../use-snake-cased-keys';
describe( 'useSnakeCasedKeys', () => {
test( 'ensures reference equality given same input', () => {
const input = { fooBar: 'fooBar' };
const { result, rerender } = renderHook( ( params ) => useSnakeCasedKeys( params ), {
initialProps: { input },
} );
const previous = result.current;
rerender( { input } );
expect( result.current ).toBe( previous );
} );
test( 'given fooBar it will convert correctly', () => {
const input = { fooBar: 'fooBar' };
const expectedOutput = { foo_bar: 'fooBar' };
const { result } = renderHook( ( params ) => useSnakeCasedKeys( params ), {
initialProps: { input },
} );
expect( result.current ).toEqual( expectedOutput );
} );
test( 'given foo_bar it will convert correctly', () => {
const input = { foo_bar: 'fooBar' };
const expectedOutput = { foo_bar: 'fooBar' };
const { result } = renderHook( ( params ) => useSnakeCasedKeys( params ), {
initialProps: { input },
} );
expect( result.current ).toEqual( expectedOutput );
} );
test( 'given foo123 it will convert correctly', () => {
const input = { foo123bar: 'fooBar' };
const expectedOutput = { foo_123_bar: 'fooBar' };
const { result } = renderHook( ( params ) => useSnakeCasedKeys( params ), {
initialProps: { input },
} );
expect( result.current ).toEqual( expectedOutput );
} );
} );
|