Skip to content

Commit

Permalink
1,419th Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyam-Chen committed Apr 4, 2024
1 parent 7ce44ef commit bc21312
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { VueWrapper } from '@vue/test-utils';
import { mount, flushPromises } from '@vue/test-utils';
import * as xui from '@x/ui';
import todos from 'mock/todos/response';

import localer from '~/plugins/localer';
import router from '~/plugins/router';

import Page from '../+page.vue';
import useStore from '../store';

let wrapper: VueWrapper;

afterEach(() => {
wrapper.unmount();
});

test('initial', async () => {
vi.spyOn(xui, 'request').mockImplementation((url, { method }: any): any => {
if (url === '/todos' && method === 'POST') {
return { _data: todos.basic, status: 200 };
}
});

wrapper = mount(Page, { global: { plugins: [router, localer] } });

await flushPromises();

const store = useStore();
expect(store.state.todosRows).toStrictEqual(todos.basic.result);
expect(store.state.todosCount).toStrictEqual(todos.basic.total);
});
13 changes: 3 additions & 10 deletions mock/src/routes/todos/+handler.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import type { FastifyInstance } from 'fastify';

import response from './response';

export default async (app: FastifyInstance) => {
app.post('', async () => {
return {
result: [
{
_id: '643e4d8f178309ee94a8dcb8',
title: 'Vue',
completed: true,
},
],
total: 1,
};
return response.basic;
});
};
15 changes: 15 additions & 0 deletions mock/src/routes/todos/response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default {
basic: {
result: [
{ _id: '1', title: 'Vue', completed: true },
{ _id: '2', title: 'Tauri', completed: true },
{ _id: '3', title: 'Fastify', completed: true },
{ _id: '4', title: 'Pulumi', completed: true },
{ _id: '5', title: 'TypeScript', completed: true },
{ _id: '6', title: 'Node.js', completed: true },
{ _id: '7', title: 'MongoDB', completed: true },
{ _id: '8', title: 'Redis', completed: true },
],
total: 8,
},
};

0 comments on commit bc21312

Please sign in to comment.