Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dczajkowski/snapshy
📸 A package for running snapshot tests in Elixir
https://github.com/dczajkowski/snapshy
elixir elixir-lang elixir-language package snapshot-testing testing
Last synced: 12 days ago
JSON representation
📸 A package for running snapshot tests in Elixir
- Host: GitHub
- URL: https://github.com/dczajkowski/snapshy
- Owner: DCzajkowski
- Created: 2019-05-04T02:38:20.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-09-15T03:28:38.000Z (about 1 year ago)
- Last Synced: 2024-09-14T07:27:57.008Z (about 2 months ago)
- Topics: elixir, elixir-lang, elixir-language, package, snapshot-testing, testing
- Language: Elixir
- Homepage: https://hexdocs.pm/snapshy
- Size: 48.8 KB
- Stars: 18
- Watchers: 2
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Snapshy
Snapshy is an Elixir package for running snapshot tests in ExUnit.
## Alternatives
When I was creating Snapshy I didn't know of any package that would support snapshot testing in Elixir. Since, I have found @assert-value's [assert_value_elixir](https://github.com/assert-value/assert_value_elixir), which is more feature-rich and more polished. If you need something very light-weight, Snapshy might be a good choice. However, if you want interactivity and more features, give [assert_value_elixir](https://hex.pm/packages/assert_value) a try :)
## Installation
Add `snapshy` to your list of dependencies in `mix.exs` and run `mix deps.get`:
```elixir
def deps do
[
# ...
{:snapshy, "~> 0.2"}
]
end
```## Overview
The way this works:
1. Add Snapshy to the test
```diff
defmodule TokenizerTest do
+ use Snapshy
use ExUnit.Case# ...
end
```2. Replace `test` with `test_snapshot`
```diff
- test "correctly tokenizes booleans" do
+ test_snapshot "correctly tokenizes booleans" do
# ...
end
```3. Replace an assertion with simple function call
```diff
- assert(
- tokens("true false") == [
- boolean: "true",
- boolean: "false"
- ]
- )
+ tokens("true false")
```The first time a snapshot will be created in `test/__snapshots__/path/to/test_file/function_name.stub`. The second time, an assertion will be made against the snapshot. If you make changes and you want to update snapshots, run `SNAPSHY_OVERRIDE=true mix test` instead of `mix test`. Verify in git every change is correct.
Alternatively, you can use a macro call instead of the `test_snapshot` macro like so:
```elixir
test "correctly tokenizes booleans" do
match_snapshot tokens("true false")
end
```
**Careful!** There can only be one `match_snapshot` call per test macro call.