redux-spec
redux-spec is a library to validate a redux store against a json schema, and to generate sample data for testing purposes.
Example
// specs.jsconst todoSpec = { id: 'todo', type: 'object', properties: { id: { $ref: 'positiveInt' }, text: { type: 'string', minLength: 1, }, completed: { type: 'boolean', } }, required: ['id', 'text', 'completed']}; const todosSpec = { id: 'todos', type: 'array', items: { $ref: 'todo'}}; const positiveInt = { id: 'positiveInt', type: 'integer', minimum: 0, exclusiveMinimum: false,};
// index.js;; const todoApp = ; const storeSpec = ; const validator = ; const store = ;
API
combineSpecs
Combine specs into a single spec.
Parameters
specs
object the top level specs that are required by the redux storedefinitions
object the reference specs used by top level specs
Examples
const storeSpec = ;
Returns object a full json-schema specification
createValidator
Create a json-schema validator that used as middleware in a redux store
Parameters
spec
object the json-schema spec to validate
Returns function a middleware function to be passed to applyMiddleware
generate
Generates sample data from json-schema spec
Parameters
spec
object the json-schema spec to validate
specErrors
The reducer used to store validation errors in the redux store;
Parameters
state
array?= [] the current stateaction
object the actionaction.type
string the action type
errors
array the list of validation errors
Examples
const todoApp = ;
Returns object the new state