Skip to content

Commit

Permalink
Merge pull request #12 from mdemichele/issue#11/fix-persistStore-tests
Browse files Browse the repository at this point in the history
Testing Improvements
  • Loading branch information
mdemichele authored Feb 24, 2025
2 parents 35d77fe + 5580aa4 commit 720985f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
25 changes: 21 additions & 4 deletions tests/persistStore.spec.ts
Original file line number Diff line number Diff line change
@@ -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<unknown, {}> = configureStore(middleware)

test('persistStore returns a Persistor object', t => {
const store: MockStoreEnhanced<unknown, {}> = 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<unknown, {}> = 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 => {
Expand Down
1 change: 1 addition & 0 deletions tests/utils/find.ts
Original file line number Diff line number Diff line change
@@ -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<string, string> or can it also be null or undefind?
export default (collection: Array<Record<string, any>>, predicate: Record<string, string>): any => {
let result = {}
collection.forEach((value: any) => {
Expand Down

0 comments on commit 720985f

Please sign in to comment.