diff --git a/tests/persistStore.spec.ts b/tests/persistStore.spec.ts index 8421a004..12ca8967 100644 --- a/tests/persistStore.spec.ts +++ b/tests/persistStore.spec.ts @@ -1,20 +1,37 @@ import test from 'ava' import sinon from 'sinon' -import configureStore from 'redux-mock-store' +import configureStore, { MockStoreCreator, MockStoreEnhanced } from 'redux-mock-store' // @TODO: Redux Mock Store is deprecated. Should update soon. import persistStore from '../src/persistStore' import { PERSIST, REHYDRATE } from '../src/constants' import find from './utils/find' - -const mockStore = configureStore([]) +import { Middleware } from 'redux' +import { Persistor } from '../src/types' + +const middleware: Middleware[] = [] +const mockStore: MockStoreCreator = configureStore(middleware) + +test('persistStore returns a Persistor object', t => { + const store: MockStoreEnhanced = mockStore() + const persistor: Persistor = persistStore(store) + t.is('object', typeof persistor) + t.is('function', typeof persistor.pause) + t.is('function', typeof persistor.persist) + t.is('function', typeof persistor.purge) + t.is('function', typeof persistor.flush) + t.is('function', typeof persistor.dispatch) + t.is('function', typeof persistor.getState) + t.is('function', typeof persistor.subscribe) +}) test('persistStore dispatches PERSIST action', t => { - const store = mockStore() + const store: MockStoreEnhanced = mockStore() persistStore(store) const actions = store.getActions() const persistAction = find(actions, { type: PERSIST }) t.truthy(persistAction) + t.is('persist/PERSIST', persistAction.type) }) test('register method adds a key to the registry', t => { diff --git a/tests/utils/find.ts b/tests/utils/find.ts index 4f31ee2b..7fca6b5c 100644 --- a/tests/utils/find.ts +++ b/tests/utils/find.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ +// @TODO: Need to specify what is the expected return value from this function. Is it Record or can it also be null or undefind? export default (collection: Array>, predicate: Record): any => { let result = {} collection.forEach((value: any) => {