dream_test/matchers/collection
Collection matchers for dream_test.
These matchers work with lists.
They’re re-exported through dream_test/assertions/should.
Usage
import dream_test/assertions/should.{
should, contain, not_contain, have_length, be_empty, or_fail_with,
}
// Check if list contains an item
users
|> should()
|> contain(alice)
|> or_fail_with("Users should include Alice")
// Check list length
get_results()
|> should()
|> have_length(3)
|> or_fail_with("Should have 3 results")
Values
pub fn be_empty(
value_or_result: types.MatchResult(List(a)),
) -> types.MatchResult(List(a))
Assert that a list is empty.
Example
get_errors()
|> should()
|> be_empty()
|> or_fail_with("Should have no errors")
pub fn contain(
value_or_result: types.MatchResult(List(a)),
expected_item: a,
) -> types.MatchResult(List(a))
Assert that a list contains a specific item.
Example
[1, 2, 3]
|> should()
|> contain(2)
|> or_fail_with("List should contain 2")
pub fn have_length(
value_or_result: types.MatchResult(List(a)),
expected_length: Int,
) -> types.MatchResult(List(a))
Assert that a list has a specific length.
Example
get_users()
|> should()
|> have_length(3)
|> or_fail_with("Should have 3 users")
pub fn not_contain(
value_or_result: types.MatchResult(List(a)),
unexpected_item: a,
) -> types.MatchResult(List(a))
Assert that a list does not contain a specific item.
Example
["a", "b", "c"]
|> should()
|> not_contain("d")
|> or_fail_with("List should not contain 'd'")