From 5df3524f59efb16d19d0d69c117dc188cb036f57 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 28 Feb 2026 16:36:56 +0100 Subject: [PATCH] fix(test-isolation): move mock creation to beforeEach in CableFirst test - Move mockChargingStation initialization from module level to beforeEach() - Declare mockChargingStation as let at describe scope per TEST_STYLE_GUIDE.md - Ensures each test receives fresh mock instances - Fixes CRITICAL test isolation violation per test audit - All 12 tests in E02 - Cable-First Transaction Flow pass --- ...P20ServiceUtils-TransactionEvent-CableFirst.test.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-TransactionEvent-CableFirst.test.ts b/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-TransactionEvent-CableFirst.test.ts index 7c8300f5..cbd47542 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-TransactionEvent-CableFirst.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-TransactionEvent-CableFirst.test.ts @@ -3,7 +3,7 @@ * @description Unit tests for OCPP 2.0 cable-first transaction flow (E02) */ import { expect } from '@std/expect' -import { afterEach, describe, it } from 'node:test' +import { afterEach, beforeEach, describe, it } from 'node:test' import { OCPP20ServiceUtils } from '../../../../src/charging-station/ocpp/2.0/OCPP20ServiceUtils.js' import { @@ -39,10 +39,12 @@ import { * - E02.FR.03: Connector status transitions reflect cable state changes */ await describe('E02 - Cable-First Transaction Flow', async () => { - const mockChargingStation = createMockOCPP20TransactionTestStation() + let mockChargingStation: ReturnType - // Reset limits and state before tests - resetLimits(mockChargingStation) + beforeEach(() => { + mockChargingStation = createMockOCPP20TransactionTestStation() + resetLimits(mockChargingStation) + }) afterEach(() => { resetConnectorTransactionState(mockChargingStation) -- 2.53.0