Skip to content

Commit

Permalink
Merge pull request #167 from AthennaIO/develop
Browse files Browse the repository at this point in the history
feat(test): explain that mocking driver also change models
  • Loading branch information
jlenon7 authored Jan 11, 2024
2 parents c19790f + a5407cf commit 0f0dfca
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions docs/testing/mocking.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,8 @@ to clean your mocks in each test 👍
### Mocking the `find()` method

Imagine that our `UserService` has a method called `findById()`
that is responsible to find a user in database by the id. To
mock this scenario, we could do the following:
that is responsible to find a user in database by the id using
an `User` model. To mock this scenario, we could do the following:

```typescript
import { UserService } from '#app/services/UserService'
Expand Down Expand Up @@ -1079,8 +1079,8 @@ export default class UserServiceTest {
### Mocking the `create()` method

Now imagine that our `UserService` has a method called `create()`
that is responsible to create a user in database. To mock this
scenario, we could do the following:
that is responsible to create a user in database using an `User`
model. To mock this scenario, we could do the following:

```typescript
import { UserService } from '#app/services/UserService'
Expand Down Expand Up @@ -1118,6 +1118,9 @@ export default class UserServiceTest {

:::tip

You are able to mock any of the methods of the database [query builder.](/docs/database/query-builder)
Mocking the methods of the `Database.driver` property gaves you
power to change the behavior of models and also `Database`
facade calls. You are able to mock any method of the
database [query builder](/docs/database/query-builder)

:::

0 comments on commit 0f0dfca

Please sign in to comment.