Skip to content

Commit

Permalink
[@redux/toolkit] Add configure store (#4327)
Browse files Browse the repository at this point in the history
* add configure store

* add tests
  • Loading branch information
Brianzchen committed Jun 7, 2022
1 parent 1c80d82 commit 12b2715
Show file tree
Hide file tree
Showing 2 changed files with 348 additions and 8 deletions.
@@ -1,6 +1,11 @@
// @flow
import { describe, it } from 'flow-typed-test';
import { createAction, createReducer } from '@reduxjs/toolkit';
import { describe, it, test } from 'flow-typed-test';
import {
createAction,
createReducer,
configureStore,
type Middleware,
} from '@reduxjs/toolkit';

describe('@redux/toolkit', () => {
describe('createAction', () => {
Expand Down Expand Up @@ -46,4 +51,61 @@ describe('@redux/toolkit', () => {
});
});
});

describe('createStore', () => {
const reducer = createReducer({}, {
'a': (state, action) => {
state.name = action.payload.name;
},
});

test('with basic reducer', () => {
configureStore({
reducer,
});
});

test('full example', () => {
const preloadedState = {
todos: [
{
text: 'Eat food',
completed: true,
},
{
text: 'Exercise',
completed: false,
},
],
visibilityFilter: 'SHOW_COMPLETED',
};
const reduxBatch: any = {};

configureStore({
reducer,
devTools: process.env.NODE_ENV !== 'production',
preloadedState,
enhancers: [reduxBatch],
})
});

test('middleware', () => {
declare var logger: Middleware<any, any>;

configureStore({
reducer,
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(logger),
})

configureStore({
reducer,
middleware: [logger],
})
});

test('errors', () => {
// $FlowExpectedError[incompatible-call]
configureStore();
})
});
});

0 comments on commit 12b2715

Please sign in to comment.