feat(test): bind text assertions to targets

This commit is contained in:
slhx agent
2026-07-13 10:07:40 +02:00
parent e70c863da7
commit 6b4bb97aaa
3 changed files with 65 additions and 5 deletions
+34
View File
@@ -17,6 +17,40 @@ fn inspects_tuple_effects() {
}));
}
#[test]
fn text_update_condition_is_bound_to_the_expected_target() {
// req: test/018
let expected_target = TestTarget(ResourceKind::Slot, 42);
let inspected = hemx_test::inspect(vec![
Effect::Put {
target: ResourceRef::unscoped(ResourceId::new(ResourceKind::Slot, 42)),
payload: Payload::Text(String::from("wrong payload")),
},
Effect::Put {
target: ResourceRef::unscoped(ResourceId::new(ResourceKind::Slot, 7)),
payload: Payload::Text(String::from("expected fragment")),
},
]);
assert!(inspected.updates_text(expected_target));
assert!(inspected.payload_contains("expected fragment"));
assert!(!inspected.updates_text_containing(expected_target, "expected fragment"));
let panic = std::panic::catch_unwind(|| {
inspected.assert_updates_text_containing(expected_target, "expected fragment");
})
.expect_err("a payload on another target must not satisfy the assertion");
let message = panic
.downcast_ref::<String>()
.map(String::as_str)
.or_else(|| panic.downcast_ref::<&str>().copied())
.expect("assertion panic must carry a message");
assert!(message.contains("expected fragment"), "{message}");
assert!(message.contains("wrong payload"), "{message}");
assert!(message.contains("ResourceId"), "{message}");
}
#[test]
fn html_update_assertion_reports_expectation_and_actual_effects() {
// req: test/018