Skip to content

Commit fccf532

Browse files
committed
Document testing signals
1 parent 11e0393 commit fccf532

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

contributing/development/core_and_modules/unit_testing.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,48 @@ These tags can be added to the test case name to modify or extend the test envir
279279

280280
You can use them together to combine multiple test environment extensions.
281281

282+
Testing signals
283+
~~~~~~~~~~~~~~~
284+
285+
The following macros can be use to test signals:
286+
287+
.. list-table::
288+
:header-rows: 1
289+
:widths: auto
290+
291+
* - Macro
292+
- Description
293+
* - ``SIGNAL_WATCH(object, "signal_name")``
294+
- Starts watching the specified signal on the given object.
295+
* - ``SIGNAL_UNWATCH(object, "signal_name")``
296+
- Stops watching the specified signal on the given object.
297+
* - ``SIGNAL_CHECK("signal_name", Vector<Vector<Variant>>)``
298+
- Checks the arguments of all fired signals. The outer vector contains each fired signal, while the inner vector contains the list of arguments for that signal. The order of signals is significant.
299+
* - ``SIGNAL_CHECK_FALSE("signal_name")``
300+
- Checks if the specified signal was not fired.
301+
* - ``SIGNAL_DISCARD("signal_name")``
302+
- Discards all records of the specified signal.
303+
304+
Below is an example demonstrating the use of these macros:
305+
306+
.. code-block:: cpp
307+
308+
//...
309+
SUBCASE("[Timer] Timer process timeout signal must be emitted") {
310+
SIGNAL_WATCH(test_timer, SNAME("timeout"));
311+
test_timer->start(0.1);
312+
313+
SceneTree::get_singleton()->process(0.2);
314+
315+
Array signal_args;
316+
signal_args.push_back(Array());
317+
318+
SIGNAL_CHECK(SNAME("timeout"), signal_args);
319+
320+
SIGNAL_UNWATCH(test_timer, SNAME("timeout"));
321+
}
322+
//...
323+
282324
Test tools
283325
----------
284326

0 commit comments

Comments
 (0)