Skip to content

Commit 2f522ac

Browse files
committed
modify test
1 parent cdb3b6b commit 2f522ac

File tree

6 files changed

+20
-177
lines changed

6 files changed

+20
-177
lines changed

__tests__/components/network.vue

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,26 @@
11
<script setup lang="ts">
2-
import { useQuery } from 'vue-query';
32
import axios from 'axios';
3+
import { reactive } from 'vue';
44
5-
const props = defineProps<{ returnError: boolean }>();
6-
7-
const { data, suspense } = useQuery(
8-
'demo',
9-
async function () {
10-
const url = props.returnError ? 'error' : 'list';
11-
const { data } = await axios.get<
12-
| {
13-
status: 'success';
14-
data: string[];
15-
}
16-
| { status: 'error'; data: string }
17-
>(url);
5+
const list = reactive<string[]>([]);
186
19-
if (data.status === 'success') {
20-
return data.data;
7+
const props = defineProps<{ returnError: boolean }>();
8+
const url = props.returnError ? 'error' : 'list';
9+
const { data } = await axios.get<
10+
| {
11+
status: 'success';
12+
data: string[];
2113
}
22-
throw new Error(data.data);
23-
},
24-
{ retry: false },
25-
);
14+
| { status: 'error'; data: string }
15+
>(url);
2616
27-
await suspense();
17+
if (data.status === 'success') list.push(...data.data);
18+
else throw new Error(data.data);
2819
</script>
2920

3021
<template>
3122
<ul id="data_list">
32-
<li v-for="(item, idx) in data" :key="idx">{{ item }}</li>
23+
<li v-for="(item, idx) in list" :key="idx">{{ item }}</li>
3324
</ul>
3425
</template>
3526

__tests__/includeAndExclude.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Caputre from './components/capture.vue';
55
import ClickTypeError from './components/typeError.vue';
66
import ClickRefError from './components/refError.vue';
77
import { mount } from '@vue/test-utils';
8-
import { defineComponent, h } from 'vue';
8+
import { defineComponent, h, onErrorCaptured } from 'vue';
99
import { describe, test, beforeEach, expect } from 'vitest';
1010

1111
let App: any;
@@ -24,6 +24,8 @@ describe('include, exclude, keepEmit', function () {
2424
emit('captured', error);
2525
};
2626

27+
onErrorCaptured(() => false);
28+
2729
return function () {
2830
return h(
2931
ErrorBoundary,

__tests__/propagation.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ describe('onErrorCaptured propagation', function () {
2727
onErrorCaptured(function (errors) {
2828
fn();
2929
props.cb?.(errors);
30+
31+
return false;
3032
});
3133

3234
return function () {

__tests__/suspense.test.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@ import { mount, flushPromises } from '@vue/test-utils';
33
import { defineComponent, h, ref, Suspense } from 'vue';
44
import Caputre from './components/capture.vue';
55
import NetworkCom from './components/network.vue';
6-
import { QueryClient } from 'vue-query';
76
import { vi, describe, test, expect } from 'vitest';
87

9-
const client = new QueryClient();
10-
118
vi.mock('axios');
129

1310
const App = defineComponent({
@@ -47,11 +44,7 @@ const App = defineComponent({
4744

4845
describe('suspense', function () {
4946
test('network and suspense', async function () {
50-
const app = mount(App, {
51-
global: {
52-
provide: { VUE_QUERY_CLIENT: client },
53-
},
54-
});
47+
const app = mount(App);
5548

5649
const loading = app.find('#loading');
5750
expect(loading.exists()).toBe(true);

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
"vitest": "^0.12.9",
6060
"vue": "^3.2.34",
6161
"vue-eslint-parser": "^9.0.2",
62-
"vue-query": "^1.25.0",
6362
"vue-tsc": "^0.34.15"
6463
},
6564
"peerDependencies": {

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)