test: refs #8647 fix warnings arraydata and vnselect
This commit is contained in:
parent
da1321ee34
commit
d31c2d55eb
src
test/vitest
|
@ -152,10 +152,22 @@ const value = computed({
|
|||
},
|
||||
});
|
||||
|
||||
const arrayDataKey =
|
||||
$props.dataKey ??
|
||||
($props.url?.length > 0 ? $props.url : ($attrs.name ?? $attrs.label));
|
||||
|
||||
const arrayData = useArrayData(arrayDataKey, {
|
||||
url: $props.url,
|
||||
searchUrl: false,
|
||||
mapKey: $attrs['map-key'],
|
||||
});
|
||||
|
||||
const computedSortBy = computed(() => {
|
||||
return $props.sortBy || $props.optionLabel + ' ASC';
|
||||
});
|
||||
|
||||
const getVal = (val) => ($props.useLike ? { like: `%${val}%` } : val);
|
||||
|
||||
watch(options, (newValue) => {
|
||||
setOptions(newValue);
|
||||
});
|
||||
|
@ -174,16 +186,6 @@ onMounted(() => {
|
|||
if ($props.focusOnMount) setTimeout(() => vnSelectRef.value.showPopup(), 300);
|
||||
});
|
||||
|
||||
const arrayDataKey =
|
||||
$props.dataKey ??
|
||||
($props.url?.length > 0 ? $props.url : ($attrs.name ?? $attrs.label));
|
||||
|
||||
const arrayData = useArrayData(arrayDataKey, {
|
||||
url: $props.url,
|
||||
searchUrl: false,
|
||||
mapKey: $attrs['map-key'],
|
||||
});
|
||||
|
||||
function findKeyInOptions() {
|
||||
if (!$props.options) return;
|
||||
return filter($props.modelValue, $props.options)?.length;
|
||||
|
@ -293,8 +295,6 @@ function nullishToTrue(value) {
|
|||
return value ?? true;
|
||||
}
|
||||
|
||||
const getVal = (val) => ($props.useLike ? { like: `%${val}%` } : val);
|
||||
|
||||
async function onScroll({ to, direction, from, index }) {
|
||||
const lastIndex = myOptions.value.length - 1;
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ import { useArrayData } from 'composables/useArrayData';
|
|||
import { useRouter } from 'vue-router';
|
||||
import * as vueRouter from 'vue-router';
|
||||
import { setActivePinia, createPinia } from 'pinia';
|
||||
import { defineComponent, h } from 'vue';
|
||||
import { mount } from '@vue/test-utils';
|
||||
|
||||
describe('useArrayData', () => {
|
||||
const filter = '{"limit":20,"skip":0}';
|
||||
|
@ -43,7 +45,7 @@ describe('useArrayData', () => {
|
|||
it('should fetch and replace url with new params', async () => {
|
||||
vi.spyOn(axios, 'get').mockResolvedValueOnce({ data: [] });
|
||||
|
||||
const arrayData = useArrayData('ArrayData', {
|
||||
const arrayData = mountArrayData('ArrayData', {
|
||||
url: 'mockUrl',
|
||||
searchUrl: 'params',
|
||||
});
|
||||
|
@ -72,7 +74,7 @@ describe('useArrayData', () => {
|
|||
data: [{ id: 1 }],
|
||||
});
|
||||
|
||||
const arrayData = useArrayData('ArrayData', {
|
||||
const arrayData = mountArrayData('ArrayData', {
|
||||
url: 'mockUrl',
|
||||
navigate: {},
|
||||
});
|
||||
|
@ -94,7 +96,7 @@ describe('useArrayData', () => {
|
|||
],
|
||||
});
|
||||
|
||||
const arrayData = useArrayData('ArrayData', {
|
||||
const arrayData = mountArrayData('ArrayData', {
|
||||
url: 'mockUrl',
|
||||
oneRecord: true,
|
||||
});
|
||||
|
@ -107,3 +109,17 @@ describe('useArrayData', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
function mountArrayData(...args) {
|
||||
let arrayData;
|
||||
|
||||
const TestComponent = defineComponent({
|
||||
setup() {
|
||||
arrayData = useArrayData(...args);
|
||||
return () => h('div');
|
||||
},
|
||||
});
|
||||
|
||||
const asd = mount(TestComponent);
|
||||
return arrayData;
|
||||
}
|
||||
|
|
|
@ -27,8 +27,16 @@ vi.mock('vue', async (importOriginal) => {
|
|||
}
|
||||
return actual.inject(key);
|
||||
}),
|
||||
onMounted: vi.fn((fn) => (fn && typeof fn === 'function' ? fn() : undefined)),
|
||||
onBeforeMount: vi.fn((fn) => (fn && typeof fn === 'function' ? fn() : undefined)),
|
||||
onUpdated: vi.fn((fn) => (fn && typeof fn === 'function' ? fn() : undefined)),
|
||||
onUnmounted: vi.fn((fn) => (fn && typeof fn === 'function' ? fn() : undefined)),
|
||||
onBeforeUnmount: vi.fn((fn) =>
|
||||
fn && typeof fn === 'function' ? fn() : undefined,
|
||||
),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock('vue-router', () => ({
|
||||
useRouter: () => ({
|
||||
push: mockPush,
|
||||
|
|
|
@ -1,5 +1,17 @@
|
|||
// This file will be run before each test file, don't delete or vitest will not work.
|
||||
import { vi } from 'vitest';
|
||||
let count = 0;
|
||||
beforeEach(() => {
|
||||
vi.spyOn(console, 'warn').mockImplementation((message) => {
|
||||
count++;
|
||||
console.error('FALLO: ', message);
|
||||
// throw new Error(`Test failed due to console.warn: ${message}`);
|
||||
});
|
||||
});
|
||||
|
||||
// afterEach(() => {
|
||||
// vi.restoreAllMocks();
|
||||
// });
|
||||
|
||||
vi.mock('axios');
|
||||
vi.mock('vue-router', () => ({
|
||||
|
|
Loading…
Reference in New Issue