github-script/__test__/async-function.test.ts
Ricky C ccf1a8e117 chore: Make test run names able to handle refactoring
`fn.name` was introduced in Node 0.10.0, so this improves test suite maintainability without changing the minimum node version.

Also added a test that for certain proves that Promises can be awaited.
2024-07-05 19:05:15 -07:00

36 lines
971 B
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
import {callAsyncFunction} from '../src/async-function'
describe(callAsyncFunction.name, () => {
test('calls the function with its arguments', async () => {
const result = await callAsyncFunction({foo: 'bar'} as any, 'return foo')
expect(result).toEqual('bar')
})
test('can await a Promise', async () => {
const result = await callAsyncFunction(
{} as any,
'return await new Promise(resolve => resolve("bar"))'
)
expect(result).toEqual('bar')
})
test(`throws an ${ReferenceError.name}`, async () => {
expect.assertions(1)
try {
await callAsyncFunction({} as any, 'proces')
} catch (err) {
expect(err).toBeInstanceOf(ReferenceError)
}
})
test('can access process', async () => {
await callAsyncFunction({} as any, 'process')
})
test('can access console', async () => {
await callAsyncFunction({} as any, 'console')
})
})