Encountering issues with NuxtJS Jest tests and attempting to build a Nuxt app to test URL's due to route name errors in some components. Here is the code snippet I tried:
beforeAll(async () => {
nuxt = new Nuxt({ ...config, server: { port: 3001 } })
await nuxt.ready()
await new Builder(nuxt).build()
await nuxt.server.listen(3001, 'localhost')
}, 30000)
However, an error occurs related to nuxt-property-decorator
not rendering @Component
blocks:
ERROR in ./components/Menu/PrimaryNavigation.vue?vue&type=script&lang=ts& (./node_modules/vue-loader/lib??vue-loader-options!./components/Menu/PrimaryNavigation.vue?vue&type=script&lang=ts&) 16:0
Module parse failed: Unexpected character '@' (16:0)
File was processed with these loaders:
* ./node_modules/vue-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| import PrimaryNavigationItem from '~/components/Menu/PrimaryNavigationItem.vue'
|
> @Component({
| components: { PrimaryNavigationItem },
| })
Shown below is my Nuxt.config.js
:
import colors from 'vuetify/es5/util/colors'
export default {
// Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode
ssr: false,
// Global page headers: https://go.nuxtjs.dev/config-head
head: {
...
},
// Global CSS: https://go.nuxtjs.dev/config-css
css: [],
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
...
// Auto import components: https://go.nuxtjs.dev/config-components
...
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
...
// Modules: https://go.nuxtjs.dev/config-modules
...
// Axios module configuration: https://go.nuxtjs.dev/config-axios
...
// Proxy
...
// Vuetify module configuration: https://go.nuxtjs.dev/config-vuetify
...
// Build Configuration: https://go.nuxtjs.dev/config-build
...
}
Additionally, here is the Jest config used:
module.exports = {
moduleNameMapper: {
...
},
moduleFileExtensions: ['ts', 'js', 'vue', 'json'],
transform: {
...
},
collectCoverage: true,
collectCoverageFrom: [
...
],
setupFiles: ['<rootDir>/test/unit/index.js'],
}