Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

How to avoid nuxt-i18n error when you doing testing with Jest? #252

Open
AlexPG96 opened this issue Sep 6, 2022 · 0 comments
Open

How to avoid nuxt-i18n error when you doing testing with Jest? #252

AlexPG96 opened this issue Sep 6, 2022 · 0 comments

Comments

@AlexPG96
Copy link

AlexPG96 commented Sep 6, 2022

This error TypeError: _vm.$t is not a function appears when I launch testing from my project components. :( I used $t('stringToTranslate') for the translations string to my multilanguage app.

I can't resolve that to get the tests passed, and I've searched different forums and i18n and Jest documentation but haven't found anything...

Anyone can help me? Thanks people!

My jest.config.js:

module.exports = {
  moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/$1',
    '^~/(.*)$': '<rootDir>/$1',
    '^vue$': 'vue/dist/vue.common.js'
  },
  moduleFileExtensions: [
    'js',
    'vue',
    'json'
  ],
  transform: {
    '^.+\\.js$': 'babel-jest',
    '.*\\.(vue)$': 'vue-jest'
  },
  collectCoverage: true,
  collectCoverageFrom: [
    '<rootDir>/components/**/*.vue',
    '<rootDir>/pages/**/*.vue'
  ],
  testEnvironment: 'jsdom'
}

and my test file:

import { shallowMount } from "@vue/test-utils";
import Autocomplete from '@/components/Autocomplete.vue';


const factory = () => {
  return shallowMount(Autocomplete, {
    propsData: {
      dataArr: [ ]
    },
  });
};

describe("Autocomplete", () => {
  test("mounts properly", () => {
    const wrapper = factory();
    expect(wrapper.isVueInstance()).toBeTruthy();
  });

  test("renders properly", () => {
    const wrapper = factory();

    expect(wrapper.html()).toMatchSnapshot();
  });
});
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant