Skip to content

Commit

Permalink
modify test
Browse files Browse the repository at this point in the history
  • Loading branch information
xyhxx committed May 13, 2023
1 parent cdb3b6b commit 2f522ac
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 177 deletions.
35 changes: 13 additions & 22 deletions __tests__/components/network.vue
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
<script setup lang="ts">
import { useQuery } from 'vue-query';
import axios from 'axios';
import { reactive } from 'vue';
const props = defineProps<{ returnError: boolean }>();
const { data, suspense } = useQuery(
'demo',
async function () {
const url = props.returnError ? 'error' : 'list';
const { data } = await axios.get<
| {
status: 'success';
data: string[];
}
| { status: 'error'; data: string }
>(url);
const list = reactive<string[]>([]);
if (data.status === 'success') {
return data.data;
const props = defineProps<{ returnError: boolean }>();
const url = props.returnError ? 'error' : 'list';
const { data } = await axios.get<
| {
status: 'success';
data: string[];
}
throw new Error(data.data);
},
{ retry: false },
);
| { status: 'error'; data: string }
>(url);
await suspense();
if (data.status === 'success') list.push(...data.data);
else throw new Error(data.data);
</script>

<template>
<ul id="data_list">
<li v-for="(item, idx) in data" :key="idx">{{ item }}</li>
<li v-for="(item, idx) in list" :key="idx">{{ item }}</li>
</ul>
</template>

Expand Down
4 changes: 3 additions & 1 deletion __tests__/includeAndExclude.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Caputre from './components/capture.vue';
import ClickTypeError from './components/typeError.vue';
import ClickRefError from './components/refError.vue';
import { mount } from '@vue/test-utils';
import { defineComponent, h } from 'vue';
import { defineComponent, h, onErrorCaptured } from 'vue';
import { describe, test, beforeEach, expect } from 'vitest';

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

onErrorCaptured(() => false);

return function () {
return h(
ErrorBoundary,
Expand Down
2 changes: 2 additions & 0 deletions __tests__/propagation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ describe('onErrorCaptured propagation', function () {
onErrorCaptured(function (errors) {
fn();
props.cb?.(errors);

return false;
});

return function () {
Expand Down
9 changes: 1 addition & 8 deletions __tests__/suspense.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import { mount, flushPromises } from '@vue/test-utils';
import { defineComponent, h, ref, Suspense } from 'vue';
import Caputre from './components/capture.vue';
import NetworkCom from './components/network.vue';
import { QueryClient } from 'vue-query';
import { vi, describe, test, expect } from 'vitest';

const client = new QueryClient();

vi.mock('axios');

const App = defineComponent({
Expand Down Expand Up @@ -47,11 +44,7 @@ const App = defineComponent({

describe('suspense', function () {
test('network and suspense', async function () {
const app = mount(App, {
global: {
provide: { VUE_QUERY_CLIENT: client },
},
});
const app = mount(App);

const loading = app.find('#loading');
expect(loading.exists()).toBe(true);
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"vitest": "^0.12.9",
"vue": "^3.2.34",
"vue-eslint-parser": "^9.0.2",
"vue-query": "^1.25.0",
"vue-tsc": "^0.34.15"
},
"peerDependencies": {
Expand Down
146 changes: 1 addition & 145 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2f522ac

Please sign in to comment.