Jump.CredoChecks.WeakAssertion (Jump.CredoChecks v0.3.0)

View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

This check has a base priority of high and works with any version of Elixir.

Explanation

Assertions like assert is_list(val) or refute is_nil(val) are almost always too weak. They pass for any value of the right type, which means the test isn't actually verifying the behavior you care about.

Instead, assert something specific about the value:

# ❌ Weak
assert is_list(result)
assert is_map(result)
assert is_binary(result)
refute is_nil(result)
refute result == nil
assert result != nil
assert not is_nil(result)
assert result
assert %{} = result
assert "" <> _ = result
assert <<_::binary>> = result
assert %{key: <<_::binary>>} = result

# ✅ Strong
assert [%Product{id: ^id}] = result
assert %{name: "Tyler"} = result
assert result == "expected string"
assert is_nil(error)
assert %Product{} = result

Check-Specific Parameters

There are no specific parameters for this check.

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.