Jump.CredoChecks.ConditionalAssertion (Jump.CredoChecks v0.4.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

Tests should be deterministic: you should be able to confidently say which branch will be taken every time the test runs. An assertion of the form assert a or b (or assert a || b) indicates you don't really know what's going on in your test.

If you genuinely don't know which value to expect, that's a signal the test setup is non-deterministic; fix the source of the non-determinism instead of papering over it in the assertion.

# ❌ Unclear expected behavior (or non-deterministic)
assert foo == :bar or baz == :bop
assert foo in [:bar, :baz] || bop in [:whiz, :bang]

# ✅ Clear, deterministic
assert foo == :bar
assert bop in [:whiz, :bang]

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.