mirror of
https://github.com/actions/github-script.git
synced 2026-02-08 03:57:27 +00:00
`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.
36 lines
971 B
TypeScript
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')
|
|
})
|
|
})
|