# Object Test Titles

#### Group using nested objects

> **NOTE** Titles must be unique.
If two titles are the same and your editor\ide doesn't detect the duplication
then only one of those tests will run.

[//js]: ./test/examples/objects/objectTestGroups.example.js[/]
```js
import * as assert from 'assert';

let testsRun = 0;

export const ObjectTestGroupingExample = {

  'test group 1': {

    ['test 1']: function () {
      // mocha test title example
      assert.equal(this.test.parent.title, 'test group 1')
      assert.equal(this.test.title, 'test 1')
      testsRun++
    }

  },

  'test group 2': {

    ['test 1']: function () {
      // mocha test title example
      assert.equal(this.test.parent.title, 'test group 2')
      assert.equal(this.test.title, 'test 1')
      testsRun++
    }

  },

  afterAll: () => assert.equal(testsRun, 2)
}
```

#### Deeply nested objects and context

Test groups are created for each level of nesting. You can provide a specific context for each level using the `testContextLookup` option.

[//js]: ./test/examples/objects/objectNestedContext.example.js[/]
```js
import * as assert from 'node:assert';

/**
 * Example demonstrating nested test context.
 * In a real runner, you would provide a `testContextLookup` function that 
 * maps the group names to specific context objects.
 */
export const ObjectNestedContextExample = {

  'level 1': {
    
    'level 2': {
      
      'test in level 2': function () {
        
        // This example shows that we can access parent names from the runner's metadata if available.
        const title = this.test.title;
        const parentTitle = this.test.parent.title;
        const grandParentTitle = this.test.parent.parent.title;

        assert.equal(title, 'test in level 2');
        assert.equal(parentTitle, 'level 2');
        assert.equal(grandParentTitle, 'level 1');
      }
    }
  }

};

```