lightsoutAlpha

async

an async unit arranged or asserted without the resolved/rejected forms the document names

Agent checkadvisory by defaultbasetests

The argument

Async

Configure with mockResolvedValue / mockRejectedValue in the setup factory; await the act in the test; assert rejections with await expect(...).rejects.toThrow(...) — the one place the act sits inside the assertion.

The proof

failsrc/users/getUserData.unit.test.ts
import { expect, describe, test, jest } from '@jest/globals';
import { getUserData } from './getUserData';

const mockFindUser = jest.fn<(id: string) => Promise<{ id: string } | null>>();

describe('getUserData', () => {
	test('rejects when the user does not exist', () => {
		mockFindUser.mockImplementation(() => Promise.reject(new Error('Not found')));

		// nothing is awaited, so the assertion runs before the rejection lands and
		// the test passes whatever the unit does
		getUserData({ findUser: mockFindUser, userId: '999' }).catch((error: Error) => {
			expect(error.message).toBe('Not found');
		});
	});
});
passsrc/users/getUserData.unit.test.ts
import { expect, describe, test, jest } from '@jest/globals';
import { getUserData } from './getUserData';

const mockFindUser = jest.fn<(id: string) => Promise<{ id: string } | null>>();

const setupUser = ({ found = true }: { found?: boolean } = {}) => {
	if (found) {
		mockFindUser.mockResolvedValue({ id: '1' });
	} else {
		mockFindUser.mockRejectedValue(new Error('Not found'));
	}

	return { findUser: mockFindUser };
};

describe('getUserData', () => {
	test('rejects when the user does not exist', async () => {
		const { findUser } = setupUser({ found: false });

		await expect(getUserData({ findUser, userId: '999' })).rejects.toThrow('Not found');
	});
});

Turn it down

Both lines go in your lightsout.config.json.

"standards-checks": { "async": "advisory" }
"standards-checks": { "async": "off" }