Vitest and `describe.concurrent` - Tests should include assertions

Hello,

Has anyone faced a similar issue?

Concurrent vitest tests via describe.concurrent are flagged by SonarCloud for missing assertions.
The tests have assertions, though the expect handler is passed through the local test context, which is required for concurrent tests.

This is explained in Test API Reference | Vitest.

describe.concurrent('createProduct', () => {
    it('should return 201 on success', async ({ expect }) => {
        await productController.createProduct(payload, okResponseFnMock, validationErrorResponseFnMock, internalErrorResponseFnMock);
        const responseData: SuccessResponseInterface = {
            message: ResponseResponseMessagesEnum.RESOURCE_CREATED,
            details: plainToInstance(MasterProduct, payload)
        };
        expect(okResponseFnMock).toHaveBeenCalledWith(201, responseData);
    });
});

If I run tests without this concurrency, the reports are fine.

Thanks,
Valentin

Hello @ValentinGurkov,

Thank you for your valuable feedback, and welcome to the Sonar community.

While we’ve recently added support for the Vitest testing library, it appears that we overlooked a specific use case involving concurrent tests. The current implementation of the rule does not consider the expect object made available through the test callback.

To address this issue promptly, I’ve created a ticket.

Best regards,

1 Like