Skip to content

Commit

Permalink
refactor: Upgraded to h3 => v1.8.0 dependency in nitro-cors.
Browse files Browse the repository at this point in the history
refactor: Upgraded to h3 => v1.8.0 dependency in nitro-cors.
  • Loading branch information
michealroberts committed Aug 28, 2023
1 parent a00b034 commit b002491
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion tests/defineCORSEventHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

/*****************************************************************************************************************/

import { describe, expect, it, suite } from 'vitest'
import { describe, expect, expectTypeOf, it, suite } from 'vitest'

import { type EventHandler, type EventHandlerRequest } from 'h3'

import { defineCORSEventHandler } from '../src'

Expand All @@ -17,5 +19,41 @@ suite('nitro-cors eventHandler', () => {
it('should be defined', () => {
expect(defineCORSEventHandler).toBeDefined()
})

it('should return the correct event handler types when specified', async () => {
const handler = defineCORSEventHandler(
async event => {
return {
cors: true
}
},
{
origin: '*',
methods: '*'
}
)

expectTypeOf(handler).toEqualTypeOf<
EventHandler<EventHandlerRequest, Promise<{ cors: boolean }>>
>()
})

it('should return the correct event handler types when specified', () => {
const handler = defineCORSEventHandler(
event => {
return {
cors: true
}
},
{
origin: '*',
methods: '*'
}
)

expectTypeOf(handler).toEqualTypeOf<EventHandler<EventHandlerRequest, { cors: boolean }>>()
})
})
})

/*****************************************************************************************************************/

0 comments on commit b002491

Please sign in to comment.