Skip to content

Commit

Permalink
Mock svg import files in jest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
guergana committed Feb 26, 2024
1 parent 7be97ca commit 9d7a64e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion jest.config.js
Expand Up @@ -12,7 +12,8 @@ module.exports = {
"transform": {
".*\\.(vue)$": "<rootDir>/node_modules/@vue/vue3-jest",
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest"
"^.+\\.tsx?$": "<rootDir>/node_modules/ts-jest",
'.+\\.svg$': '<rootDir>/tests/Vue/helpers/jest-svg-component-transformer.js'
},
// (Optional) This file helps you later for global settings
"setupFilesAfterEnv": [
Expand Down
20 changes: 20 additions & 0 deletions tests/Vue/Components/LanguageSelector.spec.js
@@ -0,0 +1,20 @@
import { mount } from '@vue/test-utils';
import LanguageSelector from '@/Components/LanguageSelector.vue';
import { createI18n } from 'vue-banana-i18n';

const i18n = createI18n({
messages: {},
locale: 'en',
wikilinks: true
});

describe('LanguageSelector.vue', () => {
it('renders', () => {
const wrapper = mount(LanguageSelector, {
global: {
plugins: [i18n],
}});

expect(wrapper.find('.mismatchfinder__language-selector').exists()).toBe(true);
});
});
12 changes: 12 additions & 0 deletions tests/Vue/helpers/jest-svg-component-transformer.js
@@ -0,0 +1,12 @@
module.exports = {
process(sourceText, sourcePath) {
const mockComponent = {
name: sourcePath,
template: sourceText
}

return {
code: `module.exports = ${JSON.stringify(mockComponent)};`
}
}
}

0 comments on commit 9d7a64e

Please sign in to comment.