Experimenting with Nuxtjs application using AVA and TypeScript

I'm in the process of developing a Nuxt application using TypeScript and intend to conduct unit testing with AVA. Nonetheless, upon attempting to run a test, I encounter the following error message:

✖ No test files were found

The @nuxt/typescript-build package has been installed and included in my nuxt.config.js

Below is an outline of the project structure (excluding items like package.json):

- components/
  - CardItem.vue
- test/
  - specs/
    -CardItem.spec.ts
  - ava.setup.js
- ava.config.cjs
- nuxt.config.js
- tsconfig.json

This represents my configuration file for ava.config.cjs:

module.exports = () => {
  return {
    require: ['./test/ava.setup.js'],
    ignoredByWatcher: ['!**/*.{js,vue}'],
    babel: true,
    tap: false,
    verbose: false,
    color: true
  }
}

This is the content of ava.setup.js:

require('browser-env')()
const hooks = require('require-extension-hooks')
const Vue = require('vue')

Vue.config.productionTip = false

window.Date = global.Date = Date

hooks('vue')
  .plugin('vue')
  .push()
hooks(['vue', 'js'])
  .exclude(({ filename }) => filename.match(/\/node_modules\//))
  .plugin('babel')
  .push()

Here is the setup from my tsconfig.json:

{
  "compilerOptions": {
    "target": "es2018",
    "module": "esnext",
    "moduleResolution": "node",
    "lib": ["esnext", "esnext.asynciterable", "dom"],
    "esModuleInterop": true,
    "allowJs": true,
    "sourceMap": true,
    "strict": true,
    "noEmit": true,
    "baseUrl": ".",
    "paths": {
      "~/*": ["./*"],
      "@/*": ["./*"]
    },
    "types": ["@types/node", "@nuxt/types"]
  },
  "exclude": ["node_modules"]
}

Lastly, here is the content of CardItem.spec.ts:

import test from 'ava'
import { shallowMount } from '@vue/test-utils'
import CardItem from '@/components/CardItem.vue'

test('renders it\'s graphic', async t => {
  const wrapper = shallowMount(CardItem)

  t.fail()
})

Answer №1

It has been noted in this source that Ava does not automatically detect typescript file extensions. To address this, it appears that integrating https://github.com/avajs/typescript is necessary. It is recommended to refer to the README provided by the latter repository for guidance.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using Vue to access values in v-model:

I need to implement validations for a form with 30 fields by using getters and setters. However, it seems I cannot have computed and data values with the same name. Some examples suggest that setting the model and the computed property as the same can wor ...

Angular 2 integration for Oauth 2 popup authorization

I am in the process of updating an existing Angular application to utilize Angular 2. One challenge I am facing is opening an OAuth flow in a new pop-up window and then using window.postMessage to send a signal back to the Angular 2 app once the OAuth proc ...

What is the best way to redirect the /register endpoint in Laravel to my single page application (SPA) application

I am seeking assistance with my SPA development in Vue. Currently, the login page serves as the root page. Route::get('/', function () { return view('auth.login'); }); Auth::routes(); Route::get('/home', 'HomeContro ...

What is the best way to set up multiple routes for a single component in React

I am currently using Vue 2 in my project and have set up the following routes: const routes = [ { path: "/suites", component: Home, }, { path: "*", component: LandingPage, }, ]; Now, I need to include an additi ...

Utilizing flatMap to implement nested service calls with parameters

Recently, I encountered an issue while working on a service call to retrieve data from a JSON file containing multiple items. After fetching all the items, I needed to make another service call to retrieve the contents of each item. I tried using flatMap f ...

Different return types of a function in Typescript when the parameter is either undefined or its type is explicitly asserted vary

Addressing Complexity This code may seem simple, but the use case it serves is quite complex: type CustomFunction = <B extends ['A']>( param?: B ) => B extends undefined ? 'TYPE_1' : 'TYPE_2' // Usage examples: co ...

Engage with the item provided to an Angular2 component as an Input parameter

In a nutshell, the issue stems from a missing 'this' when referencing the @Input'ed variables. Currently, I have a parent class that will eventually showcase a list of "QuestionComponents". The pertinent section of the parent class templat ...

Run a script in a newly opened tab using the chrome.tabs.create() method

Struggling with executing a script using chrome.tabs.executeScript() in the tab created with chrome.tabs.create()? Despite searching for solutions, nothing seems to be working as expected. Check out my current code below: runContentScript(){ c ...

Has the antd Form.create() method been substituted with something else?

I have been working on creating a login page in react using antd. I came across a tutorial that seems to be outdated as it is giving me an error. After researching on a forum, I found out that form.create() is no longer available, but I am unsure of how to ...

Concealing Rows Once a Specified Threshold of Rows Has Been Modified

My knowledge of Javascript is very basic and I am new to coding. I have created a table that updates when a button is clicked. However, I am looking for a way to limit the number of rows in my table. For example, when I add a sixth data entry to the table, ...

What is the best way to handle an OR scenario in Playwright?

The Playwright documentation explains that a comma-separated list of CSS selectors will match all elements that can be selected by one of the selectors in that list. However, when I try to implement this, it doesn't seem to work as expected. For exam ...

Enhancing the appearance of the Mui v5 AppBar with personalized styles

I am encountering an issue when trying to apply custom styles to the Mui v5 AppBar component in Typescript. import { alpha } from '@mui/material/styles'; export function bgBlur(props: { color: any; blur?: any; opacity?: any; imgUrl?: any; }) { ...

Vue.js 3 with TypeScript is throwing an error: "Module 'xxxxxx' cannot be located, or its corresponding type declarations are missing."

I developed a pagination plugin using Vue JS 2, but encountered an error when trying to integrate it into a project that uses Vue 3 with TypeScript. The error message displayed is 'Cannot find module 'l-pagination' or its corresponding type ...

The computed properties in Vue are not receiving any values when an array is passed using v-bind

Embarking on my Vue journey with a simple example, I am attempting to calculate the sum of items based on the provided data. If you wish to explore the complete example, it can be accessed in this jsffile. Here is the component structure: Vue.component(&a ...

Passing a click event to trigger a popup on another button: Tips to make it happen

I recently came across this interesting component that I am using: My current challenge involves properly passing a click event from one button to another and displaying a popup beneath the forwarded button. <script src="//unpkg.com/vue/dist/vue.js"&g ...

leveraging dynamic variables within route elements in Vue 3

I have been utilizing this breadcrumb template in my project: <route> { name: "educations-view-id-tab", meta: { pageTitle: 'Educations', breadcrumb: [ { title: 'List', to:{ name: 'educations' }, disabled:false ...

Using Firebase with Arrays in Javascript

Currently, my team and I are working on a project using Firebase with Vue.js as the framework. We've come across a challenge regarding creating, updating, and deleting elements in a Firebase cloud document. For instance, within our 'people&apos ...

The error message "Unable to access 'useContext' property of null" appeared

I am currently in the process of developing a component library using Material UI, TypeScript, and Rollup. The package has been successfully published, but I am encountering an error when trying to import it into a new project: "Uncaught TypeError: C ...

The section cannot be shown in a flex layout within a grid container

My goal is to showcase a grid layout containing multiple sections within a div, but I'm encountering an issue where the sections are only displaying as blocks. I am seeking assistance in making the second portion of the data appear flexed. Currently, ...

JavaScript ES6 array method for generating an object from an array

I wish to transform the following array: [ { event: "LIB", block_calendar: "YES", obs: "Lorem Ipsum", status: "Block", }, { event: "LIB" block_calendar: "YES" o ...