JavaScript assertion interface basic behaviors¶
This page explains the JavaScript assertion interface basic behavior.
Interface names¶
Each JavaScript assertion interface has the prefix of the assert_
(e.g., assert_equal
, assert_true
, and so on).
These interfaces are positioned in the root package so you can use them, for example, ap.assert_equal(...)
.
Assertion results¶
These interfaces display the results on the browser console, as follows:
import apysc as ap
stage: ap.Stage = ap.Stage(
stage_width=0,
stage_height=0,
background_color=ap.Color("#333"),
stage_elem_id="stage",
)
int_1: ap.Int = ap.Int(10)
ap.assert_equal(left=10, right=int_1)
ap.save_overall_html(dest_dir_path="assertion_basic_behavior_results/")
This code displays the information message on the browser console, like this (please press the F12 key to see):
[assert_equal]
Right-side variable name: i_11
Left value: 10 right value: 10
If the assertion fails, then an error message also is displayed on the browser console:
import apysc as ap
stage: ap.Stage = ap.Stage(
stage_width=0,
stage_height=0,
background_color=ap.Color("#333"),
stage_elem_id="stage",
)
int_1: ap.Int = ap.Int(10)
ap.assert_equal(left=11, right=int_1)
ap.save_overall_html(dest_dir_path="assertion_basic_behavior_results_failed/")
[assert_equal]
Right-side variable name: i_11
Left value: 11 right value: 10
...
Assertion failed:
...
Optional msg argument¶
Each assertion interface has the msg
optional argument. If you provide this argument, the error message is displayed on the browser console when an assertion fails.
import apysc as ap
stage: ap.Stage = ap.Stage(
stage_width=0,
stage_height=0,
background_color=ap.Color("#333"),
stage_elem_id="stage",
)
int_1: ap.Int = ap.Int(10)
ap.assert_equal(left=11, right=int_1, msg="Values are not equal!")
ap.save_overall_html(dest_dir_path="assertion_basic_behavior_msg/")
[assert_equal]
Right-side variable name: i_11
Left value: 11 right value: 10
...
Assertion failed: Values are not equal!