Assertions and helpers for a better JSON testing experience in Elixir.
Using ESpec? Check out test_that_json_espec.
-
is_json_equal
-
has_json_keys
-
has_only_json_keys
-
has_json_values
-
has_only_json_values
-
has_json_properties
-
has_only_json_properties
-
has_json_path
-
has_json_type
-
has_json_size
-
parse_json
-
parse_json!
-
to_json
-
to_json!
-
prettify_json
-
prettify_json!
-
to_prettified_json
-
to_prettified_json!
-
load_json
-
load_json!
- Assertions can optionally take a path
By default, to avoid needing to know the values of these ahead of time, the following keys are ignored for all JSON objects: id
, inserted_at
, and updated_at
.
This can be reconfigured as follows:
config :test_that_json,
excluded_keys: ~w(id inserted_at updated_at some other keys)
These are simple strings of "/"-separated object keys and array indexes passed to has_json_path
. For instance, with the following JSON:
{
"first_name": "Jon",
"last_name": "Snow",
"friends": [
{
"first_name": "Know",
"last_name": "Nothing"
}
]
}
We could access the first friend's first name with the path "friends/0/first_name".
Thanks to the creators and maintainers of the Ruby json_spec project for heavy inspiration.
- Add
test_that_json
as a test-only dependency inmix.exs
:
def deps do
[{:test_that_json, "~> 0.5.0", only: :test}]
end
- Tests
- Docs
- Before opening a pull request, please open an issue first.
- Do the usual fork/add/fix/run tests dance, or whatever tickles your fancy. Tests are highly encouraged.
- Open a PR.
- Treat yourself. You deserve it.
See the LICENSE file for license rights and limitations (MIT).