update: refactor assertions to work again
Some checks failed
Deploy to Cloudflare Workers with Wrangler / Deploy (push) Has been cancelled
Run Ava Tests / build (14.x) (push) Has been cancelled
Run Ava Tests / build (15.x) (push) Has been cancelled

This commit is contained in:
ThatGuySam 2025-01-11 19:40:07 -06:00
parent f76a41a2e1
commit c16868da13

View file

@ -1,4 +1,4 @@
import test from 'ava' import { describe, expect, test } from 'vitest'
import { import {
generateAPI generateAPI
@ -76,19 +76,34 @@ test( 'API has valid responses', async t => {
const apiMethod = listingCase.method( DoesItAPI ) const apiMethod = listingCase.method( DoesItAPI )
// Assert that the apiMethod url is correct // Assert that the apiMethod url is correct
t.is( (new URL(apiMethod.url)).pathname, caseEndpoint, `API endpoint '${ caseEndpoint }'` ) // t.is( (new URL(apiMethod.url)).pathname, caseEndpoint, `API endpoint '${ caseEndpoint }'` )
expect(
(new URL(apiMethod.url)).pathname,
`API endpoint '${ caseEndpoint }'`
).toBe(caseEndpoint)
// Run get request to fetch our data // Run get request to fetch our data
const result = await apiMethod.get() const result = await apiMethod.get()
// If expected is a function then call it // If expected is a function then call it
// Otherwise, compare the result to the expected
if ( typeof listingCase.expected === 'function' ) { if ( typeof listingCase.expected === 'function' ) {
t.assert( listingCase.expected( result ), `API case method check for '${ caseEndpoint }'` ) // t.assert( listingCase.expected( result ), `API case method check for '${ caseEndpoint }'` )
expect(
listingCase.expected(result),
`API case method check for '${ caseEndpoint }'`
).toBeTruthy()
continue continue
} }
t.like( result, listingCase.expected, `${ caseEndpoint } has a valid api endpoint` )
// t.like( result, listingCase.expected, `${ caseEndpoint } has a valid api endpoint` )
expect(
result,
`${ caseEndpoint } has a valid api endpoint`
).toEqual(
expect.objectContaining(listingCase.expected)
)
} }
}) })