ash/documentation/topics/testing.md

31 lines
1.1 KiB
Markdown
Raw Normal View History

2022-08-31 06:27:03 +12:00
# Testing
2023-04-14 01:24:37 +12:00
The configuration you likely want to add to your `config/test.exs` is:
```elixir
# config/test.exs
config :ash, :disable_async?, true
config :ash, :missed_notifications, :ignore
```
Each option is explained in more detail below.
2022-08-31 06:27:03 +12:00
## Async tests
The first thing you will likely want to do, especially if you are using `AshPostgres`, is to add the following config to your `config/test.exs`.
```elixir
# config/test.exs
2022-08-20 10:35:22 +12:00
config :ash, :disable_async?, true
2022-08-31 06:27:03 +12:00
```
2023-04-14 01:24:37 +12:00
This ensures that Ash does not spawn tasks when executing your requests, which is necessary for doing transactional tests with `AshPostgres`.
## Missed notifications
If you are using Ecto's transactional features to ensure that your tests all run in a transaction, Ash will detect that it had notifications to send (if you have any notifiers set up) but couldn't because it was still in a transaction. The default behavior when notifications are missed is to warn. However, this can get pretty noisy in tests. So we suggest adding the following config to your `config/test.exs`.
```elixir
# config/test.exs
config :ash, :missed_notifications, :ignore
```