question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[feature request] add built-in <i18n> block processor for vue-jest

See original GitHub issue

vue-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

nogic1008/vue-jest-i18n

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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kazuponcommented, Dec 1, 2020

@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).

1reaction
kazuponcommented, Sep 1, 2020

@nogic1008 I’ve just transferred. https://github.com/intlify/vue-i18n-jest

You can send PR! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

vue-i18n | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found