Testing on project with @t3-oss/env using vitest

When I try to write unitest on brand new create-t3-app ("initVersion": "7.13.0") with vitest installed.
// src/utils/testedfn.ts
import { env } from "@/env.mjs"
export const getmyenv = () => {
return env.DISCORD_CLIENT_ID;
}
// src/utils/testedfn.ts
import { env } from "@/env.mjs"
export const getmyenv = () => {
return env.DISCORD_CLIENT_ID;
}
// __test__/utils/testedfn.test.ts
import { env } from '@/env.mjs';
import { describe, it, expect } from 'vitest';

describe("test server env access", () => {
it("env discord is acessible", () => {
expect(env.DISCORD_CLIENT_ID).toBeDefined();
});
});
// __test__/utils/testedfn.test.ts
import { env } from '@/env.mjs';
import { describe, it, expect } from 'vitest';

describe("test server env access", () => {
it("env discord is acessible", () => {
expect(env.DISCORD_CLIENT_ID).toBeDefined();
});
});
FAIL __test__/utils/testedfn.test.ts > test server env access > env discord is acessible
Error: ❌ Attempted to access a server-side environment variable on the client
onInvalidAccess node_modules/@t3-oss/core/index.ts:134:13
Object.get node_modules/@t3-oss/core/index.ts:147:16
__test__/utils/testedfn.test.ts:7:20
5|
6| it("env discord is acessible", () => {
7| expect(env.DISCORD_CLIENT_ID).toBeDefined();
| ^
8| })
9| })
FAIL __test__/utils/testedfn.test.ts > test server env access > env discord is acessible
Error: ❌ Attempted to access a server-side environment variable on the client
onInvalidAccess node_modules/@t3-oss/core/index.ts:134:13
Object.get node_modules/@t3-oss/core/index.ts:147:16
__test__/utils/testedfn.test.ts:7:20
5|
6| it("env discord is acessible", () => {
7| expect(env.DISCORD_CLIENT_ID).toBeDefined();
| ^
8| })
9| })
I get this error. How do I configure my test runner to not be restricted to client env only? I am pretty new to this, I welcome any suggestions.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server