Unit Testing
Unit testing can be done by using the Dom::assert_eq
function, which
tests your DOM against a certain XML string:
;
You can technically also use assert_eq!(expected, got);
, however, if the test fails,
the Dom::assert_eq
error message has a much nicer format:
thread 'widgets::test_counter_ui' panicked at '
Expected DOM did not match:
expected: ----------
4
got: ----------
5
Good Practices
- Typedef the name of your DataModel in your main.rs, so that it it easier to change in future projects.
- It's also a good idea to typedef the
&'a AppState<DataModel>
and the&'a mut CallbackInfo
, in order to keep the code cleaner:
pub type DataModel = AppData;
pub type State<'a> = &'a mut ;
pub type CbInfo<'a, 'b> = &'a mut ;
This way you can avoid a bit of typing work since rustc is smart enough to infer the lifetimes - your callbacks should now look like this: