Testing $fetch
My api.ts utils:
I write this test:
And I get the error:
on this line
What is correct variant to check my apiBack function ?
export const apiBack = async <T>(
url: string,
token: string,
options: NitroFetchOptions<string> = {},
): Promise<T> => {
options.baseURL = process.env.BITRIX_API_URL
setAuthorizationHeader(options, token)
const response = await $fetch<T>(url, options)
return response as T
}export const apiBack = async <T>(
url: string,
token: string,
options: NitroFetchOptions<string> = {},
): Promise<T> => {
options.baseURL = process.env.BITRIX_API_URL
setAuthorizationHeader(options, token)
const response = await $fetch<T>(url, options)
return response as T
}I write this test:
import { describe, it, expect,} from 'vitest';
import {apiBack} from "~/utils/api";
import {testMockTokenAccess, testMockUrlRelative} from "~/utils/tests";
import { $fetch } from '@nuxt/test-utils'
describe('api Utils',()=>{
it('Проверка корректной работы запросов к беку apiBack',()=>{
apiBack(testMockUrlRelative,testMockTokenAccess)
expect($fetch).toHaveBeenCalled();
})
})import { describe, it, expect,} from 'vitest';
import {apiBack} from "~/utils/api";
import {testMockTokenAccess, testMockUrlRelative} from "~/utils/tests";
import { $fetch } from '@nuxt/test-utils'
describe('api Utils',()=>{
it('Проверка корректной работы запросов к беку apiBack',()=>{
apiBack(testMockUrlRelative,testMockTokenAccess)
expect($fetch).toHaveBeenCalled();
})
})And I get the error:
FetchError: [GET] "/catalog": 404 Cannot find any path matching /catalog.FetchError: [GET] "/catalog": 404 Cannot find any path matching /catalog.on this line
const response = await $fetch<T>(url, options) const response = await $fetch<T>(url, options)What is correct variant to check my apiBack function ?
