Nap - give your test suite a refreshing nap!

CI

Jest - inspired snapshotting test package for Elixir. It's quite general and can be used for all snapshotting purposes, not just for REST API testing.

Features:

Example

defmodule NapTestDriveTest do
use ExUnit.Case, async: true
use Nap.TestCase
defmodule MyStruct, do: defstruct a: nil, b: nil
test "normal ExUnit test" do
assert 1 == 1
end
napshot "nap snapshot test case" do
assert 1 == 1
assert_nap(currnap, 100)
assert_nap(currnap, 10.0)
assert_nap(currnap, %{a: 2})
assert_nap(currnap, {:also, :with, "tuples"})
assert_nap(currnap, "string")
assert_nap(currnap, %{a: "long
multistring
text
works fine, too"})
assert_nap(currnap, %MyStruct{a: 1, b: 2})
end
napshot "another nap snapshot test case" do
assert 1 == 1
assert_nap(currnap, %{a: 2 + 3})
end
end

Tutorial

# run with interactive snapshot update (blocks for user input)
## with async tests the STDOUT is messed up... Not sure, how to approach it properly
$ nap_interactive=true mix test / nap_i=true mix test
# update all mismatching snapshots
$ nap_update=true mix test / nap_u=true mix test
# plain run, fails on mismatching snapshots
$ mix test

Installation

If available in Hex, the package can be installed by adding nap to your list of dependencies in mix.exs:

def deps do
[
{:nap, "~> 0.1.0"}
]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/nap.

Todo

Inspiration