laravel-eloquent-spatial icon indicating copy to clipboard operation
laravel-eloquent-spatial copied to clipboard

Add Arrange-Act-Assert comments inside tests

Open MatanYadaev opened this issue 2 years ago • 0 comments

The AAA (Arrange, Act Assert) pattern's purpose is to organize your test in a way that is easier to read and understand. You can read about it here: https://github.com/goldbergyoni/javascript-testing-best-practices#-%EF%B8%8F-12-structure-tests-by-the-aaa-pattern

In this repo, all of the tests are following this pattern. But it's not perfect, because no comments are separating the test into these 3 sections.

This task is about adding these comments.

Example:

// ❌ Before
it('calculates sum', function (): void {
  $firstNumber = 1;
  $secondNumber = 2;

  $result = sum($firstNumber, $secondNumber);

  expect($result)->toBe(3);
});

// ✅ After
it('calculates sum', function (): void {
  // Arrange
  $firstNumber = 1;
  $secondNumber = 2;

  // Act
  $result = sum($firstNumber, $secondNumber);

  // Assert
  expect($result)->toBe(3);
});

Real example: https://github.com/MatanYadaev/laravel-eloquent-spatial/blob/ce02266202424a8b422a5181d46d250b6064b256/tests/SpatialBuilderTest.php#L375-L390

MatanYadaev avatar Jun 26 '23 08:06 MatanYadaev