Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Arrange-Act-Assert comments inside tests #96

Open
MatanYadaev opened this issue Jun 26, 2023 · 0 comments
Open

Add Arrange-Act-Assert comments inside tests #96

MatanYadaev opened this issue Jun 26, 2023 · 0 comments
Labels
good first issue Good for newcomers

Comments

@MatanYadaev
Copy link
Owner

MatanYadaev commented Jun 26, 2023

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:

it('calculates geometry centroid', function (): void {
// Arrange
$polygon = Polygon::fromJson('{"type":"Polygon","coordinates":[[[-1,-1],[1,-1],[1,1],[-1,1],[-1,-1]]]}');
TestPlace::factory()->create(['polygon' => $polygon]);
// Act
/** @var TestPlace $testPlace */
$testPlace = TestPlace::query()
->withCentroid('polygon')
->withCasts(['centroid' => Point::class])
->firstOrFail();
// Assert
$expectedCentroid = new Point(0, 0);
expect($testPlace->centroid)->toEqual($expectedCentroid);
});

@MatanYadaev MatanYadaev added the good first issue Good for newcomers label Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant