Skip to content

Commit 705d92d

Browse files
committed
Mock svg import files in jest tests
1 parent 7be97ca commit 705d92d

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ module.exports = {
1212
"transform": {
1313
".*\\.(vue)$": "<rootDir>/node_modules/@vue/vue3-jest",
1414
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
15-
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest"
15+
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest",
16+
'.+\\.svg$': '<rootDir>/tests/Vue/helpers/jest-svg-component-transformer.js'
1617
},
1718
// (Optional) This file helps you later for global settings
1819
"setupFilesAfterEnv": [
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { mount } from '@vue/test-utils';
2+
import LanguageSelector from '@/Components/LanguageSelector.vue';
3+
import { createI18n } from 'vue-banana-i18n';
4+
5+
const i18n = createI18n({
6+
messages: {},
7+
locale: 'en',
8+
wikilinks: true
9+
});
10+
11+
describe('LanguageSelector.vue', () => {
12+
it('renders', () => {
13+
const wrapper = mount(LanguageSelector, {
14+
global: {
15+
plugins: [i18n],
16+
}});
17+
18+
expect(wrapper.find('.mismatchfinder__language-selector').exists()).toBe(true);
19+
});
20+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
process(sourceText, sourcePath) {
3+
const mockComponent = {
4+
name: sourcePath,
5+
6+
template: sourceText
7+
}
8+
9+
return {
10+
code: `module.exports = ${JSON.stringify(mockComponent)};`
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)