test: add code snippets for generating tests
This commit is contained in:
72
.vscode/test.code-snippets
vendored
Normal file
72
.vscode/test.code-snippets
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"Test for library function": {
|
||||
"scope": "typescript",
|
||||
"isFileTemplate": true,
|
||||
"prefix": "testLib",
|
||||
"body": [
|
||||
"import { describe, expect, it } from \"bun:test\";",
|
||||
"",
|
||||
"import { $1 } from \"./$1\";",
|
||||
"",
|
||||
"describe(\"$1\", () => {",
|
||||
" it(\"$2\", () => {",
|
||||
" });",
|
||||
"});",
|
||||
"",
|
||||
],
|
||||
"description": "Test for library function",
|
||||
},
|
||||
"Test for route": {
|
||||
"prefix": "testRoute",
|
||||
"body": [
|
||||
"import { describe, expect, it } from \"bun:test\";",
|
||||
"",
|
||||
"import app from \"~/index\";",
|
||||
"import { server } from \"~/mocks\";",
|
||||
"",
|
||||
"server.listen();",
|
||||
"",
|
||||
"describe(\"requests the /$1 route\", () => {",
|
||||
" it(\"should succeed\", async () => {",
|
||||
" const res = await app.request(\"/$1\");",
|
||||
"",
|
||||
" expect(res.json()).resolves.toEqual({ success: true });",
|
||||
" expect(res.status).toBe(200);",
|
||||
" });",
|
||||
"});",
|
||||
"",
|
||||
],
|
||||
"description": "Test for route",
|
||||
},
|
||||
"Test for route with DB": {
|
||||
"prefix": "testRouteDB",
|
||||
"body": [
|
||||
"import { beforeEach, describe, expect, it } from \"bun:test\";",
|
||||
"",
|
||||
"import app from \"~/index\";",
|
||||
"import { server } from \"~/mocks\";",
|
||||
"import { getDb, resetDb } from \"~/models/db\";",
|
||||
"",
|
||||
"server.listen();",
|
||||
"",
|
||||
"describe(\"requests the /$1 route\", () => {",
|
||||
" const db = getDb({",
|
||||
" TURSO_URL: process.env.TURSO_URL ?? \"http://127.0.0.1:3000\",",
|
||||
" TURSO_AUTH_TOKEN: process.env.TURSO_AUTH_TOKEN ?? \"asd\",",
|
||||
" });",
|
||||
"",
|
||||
" beforeEach(async () => {",
|
||||
" await resetDb();",
|
||||
" });",
|
||||
"",
|
||||
" it(\"should succeed\", async () => {",
|
||||
" const res = await app.request(\"/$1\");",
|
||||
"",
|
||||
" expect(res.json()).resolves.toEqual({ success: true });",
|
||||
" expect(res.status).toBe(200); ",
|
||||
" });",
|
||||
"});",
|
||||
],
|
||||
"description": "Test for route with DB",
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user