• Run setup code before each test in the current suite. MUST be used within a describe block. Only executes if the corresponding test is enabled through testEnableControl. Useful for initializing test data, establishing connections, or setting up mock objects.

    Parameters

    • fn: () => void | Promise<void>

      Function to run before each test (can be sync or async)

    Returns void

    describe('CAN Communication Tests', () => {
    // ✅ Correct: beforeEach inside describe block
    beforeEach(async () => {
    await can.open('kvaser', 0);
    await can.setBitrate(500000);
    });

    beforeEach(() => {
    uds.setTesterPresent(true);
    uds.setTimeout(5000);
    });

    test('should send CAN message', () => {
    // Test implementation
    });
    });

    // ❌ Wrong: beforeEach outside describe block
    // beforeEach(() => { // This will not work properly });