Skip to content

Commit 834bf34

Browse files
authored
Merge pull request #18 from asmadsen/master
Improved testability; added possiblility to clear proxy cache
2 parents d6f1c0c + cd88cc3 commit 834bf34

File tree

15 files changed

+141
-49
lines changed

15 files changed

+141
-49
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ A Type Safe Solution for Vuex Modules using ES6 Classes and ES7 Decorators that
1111
- `v.1.4.0` - async/await now works with actions in mutatate mode.
1212
- `v.1.5.0` - JavaScript Support
1313
- `v.1.6.0` - NuxtJS Support.
14+
- `v.1.7.0` - Improved testability.
1415

1516
## Installation
1617
```
@@ -219,6 +220,23 @@ export class UserStore {
219220
}
220221
```
221222

223+
## How to test
224+
225+
To test components where interact with the state using a proxy, you have to create the proxy for each test, and clear the proxy cache, to keep the state clean in between tests.
226+
227+
If you are using jest, you could clear the proxy cache in the afterEach callback.
228+
```js
229+
describe('my test suite', () => {
230+
...
231+
afterEach(() => {
232+
UserStore.ClearProxyCache(UserStore)
233+
})
234+
...
235+
})
236+
```
237+
238+
To ensure your proxy is recreated for each test, the easiest way is to create the proxy inside the [component](#ok-so-what-about-vue-components). If not you could pass the proxy into the component using [provide/inject](https://vuejs.org/v2/api/#provide-inject), or mock the proxy if you are importing it from another file ie. like a [vuex manager](#vuex-manager).
239+
222240
## A note on Vuex Actions?
223241
Vuex Actions comes in two modes. A `mutate` mode and a `raw` mode. Both can be very useful.\
224242
For most of your use cases the `mutate` mode is all you'll need. The `raw` mode can be especially useful when you need access to `rootState` and `rootGetters`.\

dist/actions.js

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/actions.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/module.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { ActionRegister } from "./actions";
2-
import { _state, _mutations, _getters, _proxy, _map, _store, _namespacedPath, _actions_register, _actions, MutationFunction, GetterFunction, ActionFunction, VuexMap, _submodule, _module, _target } from "./symbols";
2+
import { _state, _mutations, _getters, _proxy, _map, _store, _namespacedPath, _actions_register, _actions, MutationFunction, GetterFunction, ActionFunction, VuexMap, _submodule, _module, _target } from './symbols';
33
import { Store } from "vuex";
44
export declare type VuexClassConstructor<T> = new () => T;
55
export declare class VuexModule {
66
static CreateSubModule<V extends typeof VuexModule>(SubModule: V): InstanceType<V>;
77
static CreateProxy<V extends typeof VuexModule>($store: Store<any>, cls: V): InstanceType<V>;
8+
static ClearProxyCache<V extends typeof VuexModule>(cls: V): void;
89
static ExtractVuexModule(cls: typeof VuexModule): {
910
namespaced: boolean;
1011
state: any;
@@ -16,7 +17,7 @@ export declare class VuexModule {
1617
modules: Record<string, any>;
1718
};
1819
}
19-
export declare function createProxy<V extends typeof VuexModule>($store: Store<any>, cls: V, cachePath: string): InstanceType<V>;
20+
export declare function createProxy<V extends typeof VuexModule>($store: Store<any>, cls: V, namespacedPath: string, cachePath: string): InstanceType<V>;
2021
export interface VuexModule {
2122
[_state]: Record<string, any>;
2223
[_mutations]: Record<string, MutationFunction>;

dist/module.js

Lines changed: 15 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)