This repository has been archived by the owner on May 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.ts
71 lines (62 loc) · 1.54 KB
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import Vue from "vue";
import Vuex from "vuex";
import { pick, send, receive } from "./src/index";
Vue.config.productionTip = false;
Vue.use(Vuex);
it("pick function", () => {
const obj = { name: "zhang", age: 10 };
// 不传参数情况
expect(pick(obj)).toStrictEqual({ name: "zhang", age: 10 });
// 传参数的情况
expect(pick(obj, ["name"])).toStrictEqual({ name: "zhang" });
});
it("send & receive without keys", done => {
const masterStore = new Vuex.Store({
state: { name: "zhang", age: 10 },
mutations: {
updateAge(state) {
state.age += 1;
}
},
plugins: [send()]
});
masterStore.commit("updateAge");
setTimeout(() => {
const slaveStore = new Vuex.Store({
state: {
age: null,
name: ""
},
plugins: [receive()]
});
expect(slaveStore.state.name).toBe("zhang");
expect(slaveStore.state.age).toBe(11);
done();
});
});
it("send & receive with keys", done => {
const masterStore = new Vuex.Store({
state: { name: "zhang", age: 10, sex: "man" },
mutations: {
updateAge(state) {
state.age += 1;
}
},
plugins: [send(["name", "sex"])]
});
masterStore.commit("updateAge");
setTimeout(() => {
const slaveStore = new Vuex.Store({
state: {
age: null,
name: "",
sex: ""
},
plugins: [receive(["name"])]
});
expect(slaveStore.state.name).toBe("zhang");
expect(slaveStore.state.age).toBe(null);
expect(slaveStore.state.sex).toBe("");
done();
});
});