-
Notifications
You must be signed in to change notification settings - Fork 55
Open
Labels
good first issueGood for newcomersGood for newcomers
Description
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:
laravel-eloquent-spatial/tests/SpatialBuilderTest.php
Lines 375 to 390 in ce02266
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); | |
}); |
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomers