fix: error when running jest
See original GitHub issue🐛 The bug
I created a jest
unit test. Inside that particular file, I imported a Vue component. This Vue component is built with @nuxtjs/composition-api
. However, when I ran the test, I encountered an error saying that the @nuxtjs/composition-api
hasn’t been added to the buildModules
in nuxt.config.js
yet. However, I had added it. I could serve it properly on the browser.
🛠️ To reproduce Steps to reproduce the behavior:
- Create a TypeScript unit test file with Jest and import a component built with
@nuxtjs/composition-api
// Navbar.spec.ts
import { describe, expect, test } from '@jest/globals';
import { mount } from '@vue/test-utils';
import Navbar from '../components/Navbar.vue';
- Run the test
- See the error
yarn run v1.22.10
$ jest
FAIL test/Navbar.spec.ts
● Test suite failed to run
You need to add `@nuxtjs/composition-api` to your buildModules in order to use it. See https://composition-api.nuxtjs.org/getting-started/setup.
at warnToAddModule (node_modules/@nuxtjs/composition-api/lib/index.js:113:9)
at components/Navbar.vue:1153:65
at Object.<anonymous> (components/Navbar.vue:1237:3)
at Object.<anonymous> (test/Navbar.spec.ts:3:1)
console.error
You need to add `@nuxtjs/composition-api` to your buildModules in order to use it. See https://composition-api.nuxtjs.org/getting-started/setup.
at warnToAddModule (node_modules/@nuxtjs/composition-api/lib/index.js:112:11)
at components/Navbar.vue:1153:65
at Object.<anonymous> (components/Navbar.vue:1237:3)
ℹ️ Additional context
Add any other context about the problem here.
This my nuxt.config.js
file
// nuxt.config.js
export default {
// Global page headers: https://go.nuxtjs.dev/config-head
head: {
title: 'Title',
htmlAttrs: {
lang: 'en',
},
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{
hid: 'description',
name: 'description',
content: 'website',
},
],
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
},
// Global CSS: https://go.nuxtjs.dev/config-css
css: [],
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [],
// Auto import components: https://go.nuxtjs.dev/config-components
components: true,
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [
// https://go.nuxtjs.dev/typescript
'@nuxt/typescript-build',
'@nuxtjs/composition-api',
'@nuxtjs/tailwindcss',
'@nuxtjs/google-fonts',
],
// Modules: https://go.nuxtjs.dev/config-modules
modules: [
// https://go.nuxtjs.dev/axios
'@nuxtjs/axios',
'nuxt-lazy-load',
],
// Axios module configuration: https://go.nuxtjs.dev/config-axios
axios: {},
// Build Configuration: https://go.nuxtjs.dev/config-build
build: {},
googleFonts: {
display: 'swap',
prefetch: true,
preconnect: true,
preload: true,
families: {
Roboto: [400, 500],
Lato: [400, 700],
Lora: [700],
},
},
};
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Troubleshooting - Jest
Troubleshooting. Uh oh, something went wrong? Use this guide to resolve issues with Jest. Tests are Failing and You Don't Know Why.
Read more >How to resolve jest error when attempting to run test suite?
Issue resolved. Issue was caused by running the tests by using the "jest" command in the terminal which is different from using the...
Read more >Troubleshooting · Jest
Use this guide to resolve issues with Jest. Tests are Failing and You Don't Know Why #. Try using the debugging support built...
Read more >How I Fixed The Unexpected Token Error In Jest
So for the Jest tests to run, it first needs to be transpiled by Babel. If you don't get it properly transpiled, you'll...
Read more >Running All Tests in Jest doesn't show the error message ...
Here is a sample project. When I run using the Jest configuration targeting just Sample.test.tsx, I see the error message. When I run...
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 Free
Top 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
Oh wow. I completely missed that on the docs. Big apologies. Thank you so much for responding.
@samnap11 Did you follow these instructions? https://composition-api.nuxtjs.org/getting-started/setup#testing-with-jest