Organize tests using behavior-driven development (BDD) patterns to improve clarity and maintainability. Group related tests using descriptive `describe` blocks for methods/scenarios, and write clear test cases that focus on testing behavior rather than implementation details.
Organize tests using behavior-driven development (BDD) patterns to improve clarity and maintainability. Group related tests using descriptive describe
blocks for methods/scenarios, and write clear test cases that focus on testing behavior rather than implementation details.
Key principles:
Example:
describe('CatsService', () => {
describe('findAll', () => {
it('should return an array of cats', async () => {
// Test the actual service behavior, don't mock what you're testing
const result = await catsService.findAll();
await expect(result).resolves.toEqual(expectedCats);
});
});
describe('create', () => {
describe('when provided valid cat data', () => {
it('should successfully create a new cat', async () => {
const newCat = { name: 'Whiskers', age: 2 };
const result = await catsService.create(newCat);
expect(result).toMatchObject(newCat);
});
});
});
});
Enter the URL of a public GitHub repository