Skip to content

Commit

Permalink
chore: Make test run names able to handle refactoring
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
Ricky C committed Jul 6, 2024
1 parent 60a0d83 commit ccf1a8e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions __test__/async-function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

import {callAsyncFunction} from '../src/async-function'

describe('callAsyncFunction', () => {
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('throws on ReferenceError', async () => {
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 {
Expand Down
2 changes: 1 addition & 1 deletion __test__/get-retry-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import {getRetryOptions} from '../src/retry-options'

describe('getRequestOptions', () => {
describe(getRetryOptions.name, () => {
test('retries disabled if retries == 0', async () => {
const [retryOptions, requestOptions] = getRetryOptions(
0,
Expand Down

0 comments on commit ccf1a8e

Please sign in to comment.