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

feat(test): explain that mocking driver also change models #167

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

:::
Loading