Merge remote-tracking branch 'origin/main' into maintainer/pr-509-fix
# Conflicts: # crates/obscura-js/src/runtime.rs
This commit is contained in:
commit
2275d8fea0
5 files changed
+162
-30
No files matched your search
@@ -1344,6 +1344,48 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn childnode_helpers_coerce_non_string_primitives_to_text() {
|
||||
let mut rt = setup_runtime(r#"<html><body><div id="p"><span id="t">x</span></div></body></html>"#);
|
||||
let before = rt
|
||||
.evaluate("(function(){var t=document.getElementById('t'); t.before(5); return t.previousSibling ? t.previousSibling.textContent : 'NULL';})()")
|
||||
.unwrap();
|
||||
assert_eq!(before, serde_json::json!("5"));
|
||||
let after = rt
|
||||
.evaluate("(function(){var t=document.getElementById('t'); t.after(true); return t.nextSibling ? t.nextSibling.textContent : 'NULL';})()")
|
||||
.unwrap();
|
||||
assert_eq!(after, serde_json::json!("true"));
|
||||
let replaced = rt
|
||||
.evaluate("(function(){var t=document.getElementById('t'); t.replaceWith(42); return document.getElementById('p').textContent;})()")
|
||||
.unwrap();
|
||||
assert!(
|
||||
replaced.as_str().unwrap().contains("42"),
|
||||
"replaceWith(42) should leave text '42': {replaced}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replace_state_without_url_preserves_current_location() {
|
||||
let mut rt = setup_runtime("<html><body></body></html>");
|
||||
let path = rt
|
||||
.evaluate(
|
||||
"(function(){history.pushState({}, '', '/dashboard'); history.replaceState({scroll:1}); return location.pathname;})()",
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(path, serde_json::json!("/dashboard"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn push_state_without_url_preserves_current_location() {
|
||||
let mut rt = setup_runtime("<html><body></body></html>");
|
||||
let path = rt
|
||||
.evaluate(
|
||||
"(function(){history.pushState({}, '', '/a'); history.pushState({b:1}); return location.pathname;})()",
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(path, serde_json::json!("/a"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_document_title() {
|
||||
let mut rt = setup_runtime("<html><head><title>Test</title></head><body></body></html>");
|
||||
|
||||
Reference in new issue
Block a user