diff --git a/src/metadata/utils/getStop.ts b/src/metadata/utils/getStop.ts index d53e787..518a9a1 100644 --- a/src/metadata/utils/getStop.ts +++ b/src/metadata/utils/getStop.ts @@ -1,11 +1,12 @@ import type { TestInvocationMetadata } from 'jest-metadata'; +import { last } from '../../utils'; import { STOP } from '../constants'; export const getStop = (testInvocation: TestInvocationMetadata) => { const lastBlock = - testInvocation.afterAll.at(-1) ?? - testInvocation.afterEach.at(-1) ?? + last(testInvocation.afterAll) ?? + last(testInvocation.afterEach) ?? testInvocation.fn; const stop1 = testInvocation.get(STOP); diff --git a/src/utils/index.ts b/src/utils/index.ts index cbc041b..bc431ec 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -5,6 +5,7 @@ export * from './hijackFunction'; export * from './isObject'; export * from './isError'; export * from './isPromiseLike'; +export * from './last'; export * from './once'; export * from './md5'; export * from './processMaybePromise'; diff --git a/src/utils/last.ts b/src/utils/last.ts new file mode 100644 index 0000000..d8c8b41 --- /dev/null +++ b/src/utils/last.ts @@ -0,0 +1,4 @@ +export function last(array: T[]): T | undefined { + // eslint-disable-next-line unicorn/prefer-at + return array[array.length - 1]; +}