Skip to content

Commit

Permalink
Add test coverage for enhancer default options
Browse files Browse the repository at this point in the history
  • Loading branch information
MatiasArriola committed Sep 24, 2021
1 parent 0a48bc1 commit e8713e0
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('index.js', () => {
rehydrateReducer: jest.fn(() => 'REHYDRATE_REDUCER')
};

let mockInit: Function;
let mockInit: jest.Mock;
let index: typeof indexModule;

beforeEach(() => {
Expand Down Expand Up @@ -168,5 +168,47 @@ describe('index.js', () => {
{ driver, ...opts }
)
});

it('calls init() with default options', () => {
let optionDefaults: any;
mockInit.mockImplementationOnce((store, rememberedKeys, opts) => {
optionDefaults = opts;
});
const store = 'the store!!!';

const driver = {
getItem() {},
setItem() {}
};

const rememberedKeys = [ 'zz', 'bb', 'kk' ];

const rootReducer = () => 'the root of the reducers';
const initialState = 'yup, initial state';
const enhancer: any = 'another enhancer';

index.rememberEnhancer(driver, rememberedKeys)(() => store)(
rootReducer, initialState, enhancer
);

expect(mockInit).toBeCalledWith(
store,
rememberedKeys,
{ driver, ...optionDefaults }
)

const stringifySpy = jest.spyOn(JSON, 'stringify');
const parseSpy = jest.spyOn(JSON, 'parse');

expect(optionDefaults).toMatchObject({
prefix : '@persist-',
persistThrottle : 100,
persistWholeStore : false
});
expect(optionDefaults.serialize('hello', 'auth')).toEqual('\"hello\"');
expect(stringifySpy).toHaveBeenCalledWith('hello');
expect(optionDefaults.unserialize('\"bye\"', 'auth')).toEqual('bye');
expect(parseSpy).toHaveBeenCalledWith('\"bye\"');
});
});
});

0 comments on commit e8713e0

Please sign in to comment.