Skip to content

Commit 6f9d869

Browse files
Merge pull request #292 from getsentry/testing-docs
add note about testing against Sentry in a user application
2 parents c9b67ae + dfbd799 commit 6f9d869

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,26 @@ You can then view the docs in your browser:
268268
$ open docs/_build/html/index.html
269269
```
270270

271+
## Testing with Sentry
272+
273+
In some cases, users may want to test that certain actions in their application cause a report to be sent to Sentry. Sentry itself does this by using [Bypass](https://github.com/PSPDFKit-labs/bypass). It is important to note that when modifying the environment configuration the test case should not be run asynchronously. Not returning the environment configuration to its original state could also affect other tests depending on how the Sentry configuration interacts with them.
274+
275+
Example:
276+
277+
```elixir
278+
test "add/2 does not raise but sends an event to Sentry when given bad input" do
279+
bypass = Bypass.open()
280+
281+
Bypass.expect(bypass, fn conn ->
282+
{:ok, _body, conn} = Plug.Conn.read_body(conn)
283+
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
284+
end)
285+
286+
Application.put_env(:sentry, :dsn, "http://public:secret@localhost:#{bypass.port}/1")
287+
MyModule.add(1, "a")
288+
end
289+
```
290+
271291
## License
272292

273293
This project is Licensed under the [MIT License](https://github.com/getsentry/sentry-elixir/blob/master/LICENSE).

0 commit comments

Comments
 (0)