]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
fix(test-isolation): move mock creation to beforeEach in CableFirst test
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 28 Feb 2026 15:36:56 +0000 (16:36 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 28 Feb 2026 15:36:56 +0000 (16:36 +0100)
- 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

tests/charging-station/ocpp/2.0/OCPP20ServiceUtils-TransactionEvent-CableFirst.test.ts

index 7c8300f5850e80044fcd17c74caad1ce4cfdb8a0..cbd475422d2df178dab7d10d46a1ad265b389974 100644 (file)
@@ -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<typeof createMockOCPP20TransactionTestStation>
 
-  // Reset limits and state before tests
-  resetLimits(mockChargingStation)
+  beforeEach(() => {
+    mockChargingStation = createMockOCPP20TransactionTestStation()
+    resetLimits(mockChargingStation)
+  })
 
   afterEach(() => {
     resetConnectorTransactionState(mockChargingStation)