Skip to content

Commit

Permalink
test: add test for route with params
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Apr 13, 2022
1 parent 41e27b4 commit e8bc4d3
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
3 changes: 3 additions & 0 deletions test/fixture/api/param/[id].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default defineEventHandler((event) => {
return event.context.params.id
})
2 changes: 1 addition & 1 deletion test/presets/aws-lambda.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { resolve } from 'pathe'
import { describe } from 'vitest'
import destr from 'destr'
import type { APIGatewayProxyEvent, APIGatewayProxyEventV2 } from 'aws-lambda'
import { setupTest, testNitro } from '../utils'
import { setupTest, testNitro } from '../tests'

describe('nitro:preset:aws-lambda', async () => {
const ctx = await setupTest('aws-lambda')
Expand Down
2 changes: 1 addition & 1 deletion test/presets/cloudflare.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { resolve } from 'pathe'
import { Miniflare } from 'miniflare'
import { describe } from 'vitest'

import { setupTest, testNitro } from '../utils'
import { setupTest, testNitro } from '../tests'

describe('nitro:preset:cloudflare', async () => {
const ctx = await setupTest('cloudflare')
Expand Down
2 changes: 1 addition & 1 deletion test/presets/node.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from 'pathe'
import { describe } from 'vitest'
import { startServer, setupTest, testNitro } from '../utils'
import { startServer, setupTest, testNitro } from '../tests'

describe('nitro:preset:node', async () => {
const ctx = await setupTest('node')
Expand Down
2 changes: 1 addition & 1 deletion test/presets/vercel.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from 'pathe'
import { describe } from 'vitest'
import { setupTest, startServer, testNitro } from '../utils'
import { setupTest, startServer, testNitro } from '../tests'

describe('nitro:preset:vercel', async () => {
const ctx = await setupTest('vercel')
Expand Down
9 changes: 7 additions & 2 deletions test/utils.ts → test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,16 @@ export function testNitro (ctx: Context, getHandler: () => TestHandler | Promise

it('API Works', async () => {
const { data: helloData } = await callHandler({ url: '/api/hello' })
const { data: heyData } = await callHandler({ url: '/api/hey' })
const { data: kebabData } = await callHandler({ url: '/api/kebab' })
expect(helloData).to.have.string('Hello API')

const { data: heyData } = await callHandler({ url: '/api/hey' })
expect(heyData).to.have.string('Hey API')

const { data: kebabData } = await callHandler({ url: '/api/kebab' })
expect(kebabData).to.have.string('hello-world')

const { data: paramsData } = await callHandler({ url: '/api/param/test_param' })
expect(paramsData).to.have.string('test_param')
})

it('handles errors', async () => {
Expand Down

0 comments on commit e8bc4d3

Please sign in to comment.