Skip to content

Commit c9c3f69

Browse files
committed
2 parents f8c77fd + 79462a3 commit c9c3f69

21 files changed

+298
-145
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ https://github.com/michaelolof/vuex-class-component/issues/27
1414
- `v.1.4.0` - async/await now works with actions in mutatate mode.
1515
- `v.1.5.0` - JavaScript Support
1616
- `v.1.6.0` - NuxtJS Support.
17+
- `v.1.7.0` - Improved testability.
1718

1819
## Installation
1920
```
@@ -222,6 +223,23 @@ export class UserStore {
222223
}
223224
```
224225

226+
## How to test
227+
228+
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.
229+
230+
If you are using jest, you could clear the proxy cache in the afterEach callback.
231+
```js
232+
describe('my test suite', () => {
233+
...
234+
afterEach(() => {
235+
UserStore.ClearProxyCache(UserStore)
236+
})
237+
...
238+
})
239+
```
240+
241+
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).
242+
225243
## A note on Vuex Actions?
226244
Vuex Actions comes in two modes. A `mutate` mode and a `raw` mode. Both can be very useful.\
227245
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`.\
@@ -271,4 +289,4 @@ Mutated Actions can access state, getters, mutations and other actions with the
271289
Raw Actions on the other hand gives you access to `rootState` and `rootGetters`. The only limitation to this appoach however is that **you can't and shouldn't use the `this` keyword.** Instead you should get back the context object with the `getRawActionContext` function and then treat the function body like a regular vuex action.
272290

273291
All actions MUST return a promise.\
274-
All actions proxies are totally type safe and can still be used normally in Vue components whether mutatated or raw.
292+
All actions proxies are totally type safe and can still be used normally in Vue components whether mutated or raw.

dist/actions.js

Lines changed: 6 additions & 4 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/getters.js

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/getters.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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
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 {
6+
$store: Store<any>;
67
static CreateSubModule<V extends typeof VuexModule>(SubModule: V): InstanceType<V>;
78
static CreateProxy<V extends typeof VuexModule>($store: Store<any>, cls: V): InstanceType<V>;
9+
static ClearProxyCache<V extends typeof VuexModule>(cls: V): void;
810
static ExtractVuexModule(cls: typeof VuexModule): {
911
namespaced: boolean;
1012
state: any;
@@ -16,7 +18,7 @@ export declare class VuexModule {
1618
modules: Record<string, any>;
1719
};
1820
}
19-
export declare function createProxy<V extends typeof VuexModule>($store: Store<any>, cls: V, cachePath: string): InstanceType<V>;
21+
export declare function createProxy<V extends typeof VuexModule>($store: Store<any>, cls: V, namespacedPath: string, cachePath: string): InstanceType<V>;
2022
export interface VuexModule {
2123
[_state]: Record<string, any>;
2224
[_mutations]: Record<string, MutationFunction>;

dist/module.js

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

0 commit comments

Comments
 (0)