8000 test: move "expect" out of "setup" · e3d/vue-function-api@a2318ee · GitHub
[go: up one dir, main page]

Skip to content

Commit a2318ee

Browse files
committed
test: move "expect" out of "setup"
"expect" doesn't functional in "setup"
1 parent b1f6e76 commit a2318ee

File tree

3 files changed

+45
-49
lines changed

3 files changed

+45
-49
lines changed

test/functions/inject.spec.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ describe('Hooks provide/inject', () => {
7676

7777
it('should return wrapper values', done => {
7878
const State = Symbol();
79+
let obj;
7980
const app = new Vue({
8081
template: `<child/>`,
8182
setup() {
@@ -85,17 +86,15 @@ describe('Hooks provide/inject', () => {
8586
child: {
8687
template: `<div>{{ state.msg }}</div>`,
8788
setup() {
88-
const obj = inject(State);
89-
expect(obj.value.msg).toBe('foo');
90-
89+
obj = inject(State);
9190
return {
9291
state: obj,
9392
};
9493
},
9594
},
9695
},
9796
}).$mount();
98-
97+
expect(obj.value.msg).toBe('foo');
9998
app.$children[0].state.msg = 'bar';
10099
waitForUpdate(() => {
101100
expect(app.$el.textContent).toBe('bar');
@@ -104,6 +103,7 @@ describe('Hooks provide/inject', () => {
104103

105104
it('should warn when assign to a injected value', () => {
106105
const State = Symbol();
106+
let obj;
107107
new Vue({
108108
template: `<child/>`,
109109
setup() {
@@ -112,15 +112,14 @@ describe('Hooks provide/inject', () => {
112112
components: {
113113
child: {
114114
setup() {
115-
const obj = inject(State);
116-
expect(obj.value.msg).toBe('foo');
117-
obj.value = {};
118-
expect(warn.mock.calls[0][0]).toMatch(
119-
"[Vue warn]: The injectd value can't be re-assigned."
120-
);
115+
obj = inject(State);
121116
},
117+
template: `<div/>`,
122118
},
123119
},
124120
}).$mount();
121+
expect(obj.value.msg).toBe('foo');
122+
obj.value = {};
123+
expect(warn.mock.calls[0][0]).toMatch("[Vue warn]: The injectd value can't be re-assigned");
125124
});
126125
});

test/functions/state.spec.js

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,36 +45,32 @@ describe('Hooks state', () => {
4545
});
4646

4747
it('should be unwrapping(nested property inside a reactive object)', () => {
48-
new Vue({
49-
setup() {
50-
const count = value(0);
51-
const count1 = value(0);
52-
const obj = state({
53-
count,
54-
a: {
55-
b: count1,
56-
c: 0,
57-
},
58-
});
48+
const count = value(0);
49+
const count1 = value(0);
50+
const obj = state({
51+
count,
52+
a: 6D40 {
53+
b: count1,
54+
c: 0,
55+
},
56+
});
5957

60-
expect(obj.count).toBe(0);
61-
expect(obj.a.b).toBe(0);
62-
expect(obj.a.c).toBe(0);
58+
expect(obj.count).toBe(0);
59+
expect(obj.a.b).toBe(0);
60+
expect(obj.a.c).toBe(0);
6361

64-
obj.count++;
65-
expect(obj.count).toBe(1);
66-
expect(count.value).toBe(1);
67-
expect(count1.value).toBe(0);
62+
obj.count++;
63+
expect(obj.count).toBe(1);
64+
expect(count.value).toBe(1);
65+
expect(count1.value).toBe(0);
6866

69-
count.value++;
70-
count1.value++;
71-
obj.a.b++;
72-
obj.a.c = 3;
73-
expect(obj.count).toBe(2);
74-
expect(count1.value).toBe(2);
75-
expect(obj.a.b).toBe(2);
76-
expect(obj.a.c).toBe(3);
77-
},
78-
});
67+
count.value++;
68+
count1.value++;
69+
obj.a.b++;
70+
obj.a.c = 3;
71+
expect(obj.count).toBe(2);
72+
expect(count1.value).toBe(2);
73+
expect(obj.a.b).toBe(2);
74+
expect(obj.a.c).toBe(3);
7975
});
8076
});

test/setup.spec.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,18 @@ describe('setup', () => {
1111
warn.mockRestore();
1212
});
1313

14-
it('should reveive props as first params', done => {
14+
it('should reveive props as first params', () => {
15+
let props;
1516
new Vue({
1617
props: ['a'],
17-
setup(props) {
18-
expect(props.a).toBe(1);
19-
done();
18+
setup(_props) {
19+
props = _props;
2020
},
2121
propsData: {
2222
a: 1,
2323
},
24-
});
24+
}).$mount();
25+
expect(props.a).toBe(1);
2526
});
2627

2728
it('should reveive context second params', done => {
@@ -244,8 +245,8 @@ describe('setup', () => {
244245
name: null,
245246
nested: {
246247
object: {
247-
msg: 'foo'
248-
}
248+
msg: 'foo',
249+
},
249250
},
250251
};
251252
},
@@ -257,16 +258,16 @@ describe('setup', () => {
257258
waitForUpdate(() => {
258259
expect(vm.$el.textContent).toBe('foo, bar');
259260
}).then(done);
260-
})
261+
});
261262

262263
it('should make returned plain value reactive (object)', done => {
263264
const vm = new Vue({
264265
setup() {
265266
return {
266267
form: {
267268
a: 1,
268-
b: 2
269-
}
269+
b: 2,
270+
},
270271
};
271272
},
272273
template: '<div>{{ form.a }}, {{ form.b }}</div>',
@@ -276,5 +277,5 @@ describe('setup', () => {
276277
waitForUpdate(() => {
277278
expect(vm.$el.textContent).toBe('2, 3');
278279
}).then(done);
279-
})
280+
});
280281
});

0 commit comments

Comments
 (0)
0