Skip to content

Commit 892c1f6

Browse files
committed
feat: add assert_not_called test double
1 parent ca71c26 commit 892c1f6

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

docs/test-doubles.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,26 @@ function test_failure() {
156156
}
157157
```
158158
:::
159+
160+
## assert_not_called
161+
> `assert_not_called "spy"`
162+
163+
Reports an error if `spy` has been executed at least once.
164+
165+
::: code-group
166+
```bash [Example]
167+
function test_success() {
168+
spy ps
169+
170+
assert_not_called ps
171+
}
172+
173+
function test_failure() {
174+
spy ps
175+
176+
ps
177+
178+
assert_not_called ps
179+
}
180+
```
181+
:::

src/test_doubles.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,9 @@ function assert_have_been_called_times() {
141141

142142
state::add_assertions_passed
143143
}
144+
145+
function assert_not_called() {
146+
local command=$1
147+
local label="${2:-$(helper::normalize_test_function_name "${FUNCNAME[1]}")}"
148+
assert_have_been_called_times 0 "$command" "$label"
149+
}

tests/unit/test_doubles_test.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,19 @@ function test_spy_called_with_different_arguments() {
147147
assert_have_been_called_with "first_a first_b" ps 1
148148
assert_have_been_called_with "second" ps 2
149149
}
150+
151+
function test_successful_not_called() {
152+
spy ps
153+
154+
assert_not_called ps
155+
}
156+
157+
function test_unsuccessful_not_called() {
158+
spy ps
159+
160+
ps
161+
162+
assert_same \
163+
"$(console_results::print_failed_test \"Unsuccessful not called\" \"ps\" \"to has been called\" \"0 times\" \"actual\" \"1 times\")" \
164+
"$(assert_not_called ps)"
165+
}

0 commit comments

Comments
 (0)