• Create a test group to organize related test cases. Required container for all test hook functions (before, after, beforeEach, afterEach). Groups tests logically and provides a scope for shared setup/teardown operations. Automatically increments test counter for proper test enable control tracking.

    Parameters

    • name: string

      Test group name that describes the functionality being tested

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

      Test group function containing test cases and hooks

    Returns void

    // ✅ Correct: All hooks must be inside describe blocks
    describe('CAN Communication Tests', () => {
    before(async () => {
    // One-time setup for the entire test suite
    await hardware.initialize();
    });

    beforeEach(async () => {
    // Setup before each test
    await can.open('kvaser', 0);
    });

    test('should send CAN message', () => {
    const result = can.send({ id: 0x123, data: [0x01, 0x02] });
    assert.equal(result, true);
    });

    test('should receive CAN message', async () => {
    const msg = await can.recv(1000);
    assert.notEqual(msg, null);
    });

    afterEach(async () => {
    // Cleanup after each test
    await can.close();
    });

    after(() => {
    // Final cleanup for the entire test suite
    console.log('All CAN tests completed');
    });
    });

    // ❌ Wrong: Hooks outside describe blocks will not work
    // before(() => { // This is invalid });
    // beforeEach(() => { // This is invalid });
    // test('standalone test', () => { // This works but hooks don't apply });