[feature request] add built-in <i18n> block processor for vue-jest
See original GitHub issuevue-jest
supports to process custom block like <i18n>
since v4.0.0-beta.3
.
But, to use it, We have to write our own processor for each project.
In addition, we need to add some packages to interpret json5 and yaml.
Built-in custom block processor avoids this task.
Usage
jest.config.js
module.exports = {
globals: {
'vue-jest': {
transform: {
'i18n': require('vue-i18n')
}
}
}
}
component.vue
<i18n>
{
"en": {
"hello": "Hello, World"
},
"ja": {
"hello": "こんにちは、世界"
},
}
</i18n>
<template>
<div>{{ $t('hello') }}</div>
</template>
component.test.js
import { createLocalVue, mount } from '@vue/test-utils'
import VueI18n from 'vue-i18n'
import Component from './component.vue'
const localVue = createLocalVue()
localVue.use(VueI18n)
describe('./component.vue', () => {
test.each([
['en', 'Hello, World'],
['ja', 'こんにちは、世界']
])('locale %s renders "%s"', (locale, expected) => {
const i18n = new VueI18n({ locale, silentFallbackWarn: true })
const wrapper = mount(Component, { localVue, i18n })
expect(wrapper.text()).toBe(expected)
})
})
Sample
index.js
/**
* Process the content inside of a custom block and prepare it for execution in a testing environment
* @param {SFCCustomBlock[]} blocks All of the blocks matching your type, returned from `@vue/component-compiler-utils`
* @param {string} vueOptionsNamespace The internal namespace for a component's Vue Options in vue-jest
* @param {string} filename The SFC file being processed
* @param {Object} config The full Jest config
* @returns {string} The code to be output after processing all of the blocks matched by this type
*/
export function process({ blocks, vueOptionsNamespace, filename, config }) {
// ...
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
kazupon/vue-i18n (Raised $130.00) - Issuehunt
[feature request] add built-in <i18n> block processor for vue-jest. Unfunded#984created bynogic1008. $0.00. Error: You cannot call "get" on a collection ...
Read more >The Ultimate Vue Localization Guide | Phrase
Dive into Vue localization and learn how to plug the Vue I18n library into your app, so you can make it accessible to...
Read more >Vue-jest: Jest Vue Transformer - Morioh
Once you have your transformer, you'll add an entry to vue-jest's transform map. This is how vue-i18n's <i18n> custom blocks are supported in...
Read more >Angular i18n: internationalization & localization with examples
Angular I18n uses the built-in module for internationalization. Learn how to set up I18n, perform translations, and deploy the app.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@nogic1008 I’m very sorry for being so late in replying, due to development of vue-i18n-next. 🙇
If you still have motivation, can I ask you to send me a PR to the repo I have prepared? The repo I prepared has my code, but it’s fine to have it rewritten from full scratch. 🆗 https://github.com/intlify/vue-i18n-jest
The following documentation from vue-jest@v4 provides a custom processor. https://github.com/vuejs/vue-jest#supporting-custom-blocks
So it is not an official vue-jest plugin, but an official cusotom processor provided by vue-i18n (or intlify project).
@nogic1008 I’ve just transferred. https://github.com/intlify/vue-i18n-jest
You can send PR! 😃