All files / tests/views/bank index.spec.ts

100% Statements 66/66
100% Branches 4/4
100% Functions 0/0
100% Lines 66/66

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 671x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import { mount } from '@vue/test-utils';
import { expect, describe, it, vi, beforeEach } from 'vitest';
import { installQuasar } from '@quasar/quasar-app-extension-testing-unit-vitest';
import Index from '@/views/bank/Index.vue';
import { getBanks } from '@/common/api/api';
 
/* 
 * Init and Install Quasar component as plugin test context
 */
installQuasar()
 
/* 
 * Mocking Vue Router ( useRouter() ) and this should in root.
 * You can't put vi.mock() inside of describe() or test().
 */
const vueRouterMock = vi.fn();
vi.mock('vue-router', () => ({
    useRouter: () => ({
        push: vueRouterMock,
        go: vueRouterMock,
    }),
}));
 
/*
 * Reset All mocking data for fresh context
 */
beforeEach(() => { vi.restoreAllMocks(), vi.useFakeTimers() })
 
 
describe('Test case bank/add', () => {
    it('Index.vue should exists', () => {
        expect(Index).toBeTruthy();
    })
 
    it('Index.vue load post', async () => {
        const client = await import('@/common/api/axios')
        const wrapper = mount(Index);
 
        const res = {
            data: [{
                "id": -1,
                "code": "ALLO",
                "name": "ALLO",
                "createdAt": "2022-01-01T00:00:00Z",
                "logo": {
                    "kind": "WEBP",
                    "filename": "allobank.webp",
                    "url": "images/fixed-income-banks/allobank.webp"
                },
                "description": "ALLO BANK INDONESIA",
                "status": 200
            }]
        }
 
        // axios get
        client.axiosInstance.get = vi.fn().mockResolvedValue(res);
        const banks = await getBanks();
        expect(client.axiosInstance.get).toHaveBeenCalled();
 
        expect(banks).toEqual(res);
        expect(banks.data[0].name).toBe(res.data[0].name)
 
        // TODO Row not rendered
        // expect(wrapper.find('table.td').text()).toContain(res.data[0].name)
    })
})