refactor [P-137]: убраны варнинги
This commit is contained in:
1 parent
bdce08fb73
commit
1a553dfa5e
4 files changed
+101
-3
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
testEnvironment: 'jest-environment-jsdom',
|
testEnvironment: 'jest-environment-jsdom',
|
||||||
setupFiles: ['<rootDir>/jest.setup.js'],
|
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
|
||||||
transform: {
|
transform: {
|
||||||
'^.+\\.vue$': '@vue/vue3-jest',
|
'^.+\\.vue$': '@vue/vue3-jest',
|
||||||
'^.+\\.mjs$': 'babel-jest',
|
'^.+\\.mjs$': 'babel-jest',
|
||||||
|
|||||||
+15
-1
@@ -1,4 +1,3 @@
|
|||||||
import { jest } from '@jest/globals';
|
|
||||||
import * as VueCompilerDOM from '@vue/compiler-dom';
|
import * as VueCompilerDOM from '@vue/compiler-dom';
|
||||||
import * as VueServerRenderer from '@vue/server-renderer';
|
import * as VueServerRenderer from '@vue/server-renderer';
|
||||||
import * as Vue from 'vue';
|
import * as Vue from 'vue';
|
||||||
@@ -32,3 +31,18 @@ jest.mock('axios', () => {
|
|||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/* eslint-disable */
|
||||||
|
const originalWarn = console.warn;
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.spyOn(console, 'warn').mockImplementation((message) => {
|
||||||
|
if (!message.includes('resolveComponent can only be used in render() or setup()')) {
|
||||||
|
originalWarn(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
console.warn.mockRestore();
|
||||||
|
});
|
||||||
|
/* eslint-enable */
|
||||||
@@ -173,7 +173,6 @@ export default {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.titles {
|
.titles {
|
||||||
font-family: cursive !important;
|
font-family: cursive !important;
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
import { mount } from '../../../../node_modules/@vue/test-utils';
|
||||||
|
import CarouselList from '@/components/carousel-list.vue';
|
||||||
|
|
||||||
|
// Мок axios
|
||||||
|
jest.mock('@/utils/axios-api', () => ({
|
||||||
|
baseURL: 'http://example.com/',
|
||||||
|
axiosApiInstance: {
|
||||||
|
get: jest.fn(),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Мок alert store
|
||||||
|
jest.mock('@/store/useAlertStore', () => ({
|
||||||
|
useAlertStore: () => ({
|
||||||
|
alert: {
|
||||||
|
alert: false,
|
||||||
|
text: '',
|
||||||
|
color: '',
|
||||||
|
ico: '',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('CarouselList.vue', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
const { axiosApiInstance } = require('@/utils/axios-api');
|
||||||
|
axiosApiInstance.get.mockClear();
|
||||||
|
Object.defineProperty(document, 'exitFullscreen', {
|
||||||
|
writable: true,
|
||||||
|
value: jest.fn(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('вызывает axiosApiInstance.get при монтировании', async () => {
|
||||||
|
const { axiosApiInstance } = require('@/utils/axios-api');
|
||||||
|
axiosApiInstance.get.mockResolvedValue({ data: { mess: '', result: [] } });
|
||||||
|
|
||||||
|
const wrapper = mount(CarouselList, {
|
||||||
|
global: {
|
||||||
|
stubs: ['v-carousel', 'v-carousel-item'],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await wrapper.vm.$nextTick();
|
||||||
|
expect(axiosApiInstance.get).toHaveBeenCalledWith('api/navigation/carousels/');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('устанавливает большой интервал, если текущий слайд – видео', async () => {
|
||||||
|
const wrapper = mount(CarouselList, {
|
||||||
|
global: {
|
||||||
|
stubs: ['v-carousel', 'v-carousel-item'],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Создаём фейковый элемент видео
|
||||||
|
wrapper.vm.videoElement = [{ pause: jest.fn(), currentSrc: '' }];
|
||||||
|
|
||||||
|
wrapper.vm.carous = [{ link: '/video.mp4' }];
|
||||||
|
wrapper.vm.currentslide = 0;
|
||||||
|
await wrapper.vm.$nextTick();
|
||||||
|
|
||||||
|
wrapper.vm.slidechanged();
|
||||||
|
expect(wrapper.vm.interval).toBe(10000000000);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('обрабатывает событие ended', async () => {
|
||||||
|
const wrapper = mount(CarouselList, {
|
||||||
|
global: {
|
||||||
|
stubs: ['v-carousel', 'v-carousel-item'],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const fakeEvent = {
|
||||||
|
target: {
|
||||||
|
currentTime: 5,
|
||||||
|
pause: jest.fn(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
wrapper.vm.ended(fakeEvent);
|
||||||
|
expect(fakeEvent.target.currentTime).toBe(0);
|
||||||
|
expect(fakeEvent.target.pause).toHaveBeenCalled();
|
||||||
|
expect(document.exitFullscreen).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user