Skip to content

Commit

Permalink
fix: afterAll.at is not a function
Browse files Browse the repository at this point in the history
Resolves #25
  • Loading branch information
noomorph committed Feb 13, 2024
1 parent 7f2606a commit 55616db
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/metadata/utils/getStop.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 4 additions & 0 deletions src/utils/last.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function last<T>(array: T[]): T | undefined {
// eslint-disable-next-line unicorn/prefer-at
return array[array.length - 1];
}

0 comments on commit 55616db

Please # to comment.