UNPKG

react-url-query

Version:

A library for managing state through query parameters in the URL in React. Works well with or without Redux and React Router.

69 lines (60 loc) 2.02 kB
import { replaceInUrlQueryFromAction, replaceUrlQueryFromAction, multiReplaceInUrlQueryFromAction, pushInUrlQueryFromAction, pushUrlQueryFromAction, multiPushInUrlQueryFromAction, } from '../updateUrlQueryFromAction'; import { replaceInUrlQuery, replaceUrlQuery, multiReplaceInUrlQuery, pushInUrlQuery, pushUrlQuery, multiPushInUrlQuery, } from '../../updateUrlQuery'; // mock this module so we can test if it as called with correct args jest.mock('../../updateUrlQuery'); it('replaceInUrlQueryFromAction extracts correct args from action', () => { replaceInUrlQueryFromAction( { payload: { queryParam: 'foo', encodedValue: '94' } }, 'location' ); expect(replaceInUrlQuery).toBeCalledWith('foo', '94', 'location'); }); it('pushInUrlQueryFromAction extracts correct args from action', () => { pushInUrlQueryFromAction( { payload: { queryParam: 'foo', encodedValue: '94' } }, 'location' ); expect(pushInUrlQuery).toBeCalledWith('foo', '94', 'location'); }); it('multiReplaceInUrlQueryFromAction extracts correct args from action', () => { multiReplaceInUrlQueryFromAction( { payload: { encodedQuery: { foo: '94' } } }, 'location' ); expect(multiReplaceInUrlQuery).toBeCalledWith({ foo: '94' }, 'location'); }); it('multiPushInUrlQueryFromAction extracts correct args from action', () => { multiPushInUrlQueryFromAction( { payload: { encodedQuery: { foo: '94' } } }, 'location' ); expect(multiPushInUrlQuery).toBeCalledWith({ foo: '94' }, 'location'); }); it('replaceUrlQueryFromAction extracts correct args from action', () => { replaceUrlQueryFromAction( { payload: { encodedQuery: { foo: '94' } } }, 'location' ); expect(replaceUrlQuery).toBeCalledWith({ foo: '94' }, 'location'); }); it('pushUrlQueryFromAction extracts correct args from action', () => { pushUrlQueryFromAction( { payload: { encodedQuery: { foo: '94' } } }, 'location' ); expect(pushUrlQuery).toBeCalledWith({ foo: '94' }, 'location'); });