Loading Depth Study
Preparing your workspace
AAA separates test setup, the action being tested, and the expected result.
A clear test should be easy to read. Arrange prepares the required data and conditions. Act performs the operation being tested. Assert checks the result. Keeping these parts visually and logically separate helps other developers understand what the test is proving. Some tests may use fewer visible sections, but the mental structure remains useful.
A login test can arrange a valid user, act by calling the login function, and assert that authentication succeeds.
it('returns a passing result for a high score', () => {
// Arrange
const score = 85;
// Act
const result = score >= 40;
// Assert
expect(result).toBe(true);
});The test passes because a score of 85 satisfies the passing condition.