vuex-assert
Assertion for Vuex state
Examples
Just add assertions
into your Vuex modules.
// modules/users.js state: isLoading: false error: null users: assertions: isLoading: boolean error: optional users: // ... module getters, actions and mutations ...
Add assertPlugin
to plugins option of Vuex.Store
with your modules.
const store = modules plugins:
Then, the store state will be validated for every mutation. Like following message will be printed if the assertion is failed.
state.users.error.code == null
number is expected
API
-
class Assertion
-
optional: Assertion
Get assertion for optional type of this assertion.
-
assert(fn: (value: any) => boolean, message?: string): Assertion
Include additional assertion for this assertion.
-
-
assertPlugin(options): VuexPlugin
Create Vuex plugin with options.
options.assertions: { [key: string]: Assertion }
options.modules: { [key: string]: VuexModule }
-
assert(fn: (value: any) => boolean, message?: string): Assertion
Create new assertion.
-
number: Assertion
Assertion for number.
-
string: Assertion
Assertion for string.
-
boolean: Assertion
Assertion for boolean.
-
optional: Assertion
Assertion for null or undefined.
-
object(assertions?: { [key: string]: Assertion }, message?: string): Assertion
Create assertion for object with properties assertions.
-
array(assertion?: Assertion, message?: string): Assertion
Create assertion for array with items assertions.
-
and(assertions: Assertion[]): Assertion
Intersect given assertions.
-
or(assertions: Assertion[]): Assertion
Union given assertions.
License
MIT