I am coming from a Laravel background, where I can create a “Feature test” which goes something like this:
public function test_user_can_register()
{
// Arrange
$userData = [
'name' => 'John Doe',
'email' => '[email protected]',
'password' => 'password123',
];
// Create a user using the factory
$user = User::factory()->create($userData);
// Act
$response = $this->post('/register', $userData);
// Assert
$response->assertStatus(302);
$response->assertRedirect('/home');
$this->assertDatabaseHas('users', ['email' => '[email protected]']);
}
Questions related to testing in NestJS:
- There are a
controller.spec
andservice.spec
files. Why is that? why not just use the controller to write my “Feature test”. What is the point ofservice.spec
file? - In Laravel, there is (model-factories) and (resetting-the-database-after-each-test) concepts, is there something similar like this in NestJS?