Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Server utils composable is not defined in test #732

Closed
PoloLacoste opened this issue Jan 23, 2024 · 1 comment
Closed

Server utils composable is not defined in test #732

PoloLacoste opened this issue Jan 23, 2024 · 1 comment

Comments

@PoloLacoste
Copy link

Environment

  • Operating System: Windows_NT
  • Node Version: v21.6.0
  • Nuxt Version: 3.9.3
  • CLI Version: 3.10.0
  • Nitro Version: 2.8.1
  • Package Manager: pnpm@8.14.3
  • Builder: -
  • User Config: modules, devtools
  • Runtime Modules: @nuxt/test-utils/module@3.10.0
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-7fr8te?file=test%2Fapp.test.ts

Describe the bug

Inserver/domain I created a TestService class which is importing a composable from server/utils.

server/utils/test.ts :

export const useTest = () => {
  return 1
}

server/domain/test-service.ts :

export class TestService {
  private test = useTest()
}

When I initialize the TestService class inside an api endpoint it works, but when I try to initialize the same class inside a test this error appears ReferenceError: useTest is not defined.

test/app.test.ts :

// @vitest-environment nuxt
import { expect, test } from 'vitest';
import { TestService } from '~/server/domain/test-service';

test('my test', () => {
  const service = new TestService();
  expect(service).toBeDefined();
});

Additional context

No response

Logs

No response

@danielroe
Copy link
Member

Nitro server environment is not yet supported - the environment provided is a client-side runtime vitest environment.

You can track this feature in #531.

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants