1

I want to use aliases in tests files with vitest:

import { describe, expect, it } from 'vitest'
import Plan from '@/modules/Pricing/models/Plan'

let plan: Plan

describe('Plan model', () => {
  it('should bind properties correctly', () => {
    plan = new Plan({ id: 1234, name: 'columbo', price: 999 })

    expect(plan).toEqual({ id: 1234, name: 'columbo', price: 999 })
  })
})

It's a Nuxt app, I tried to configure the alias in nuxt.config.ts:

export default defineNuxtConfig({
  ssr: true,
  vite: {
    resolve: {
      alias: [
        { find: '@', replacement: path.resolve(__dirname, '.') }
      ]
    }
  },
// ...
})

When I start the test, I got this error:

enter image description here

1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.