Skip to content

Commit

Permalink
enable disabled test, fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
hamza1311 committed Aug 8, 2022
1 parent 27efd0a commit 866dbe6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 21 deletions.
22 changes: 18 additions & 4 deletions examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 16 additions & 13 deletions packages/yew/src/dom_bundle/btag/attributes.rs
Expand Up @@ -269,45 +269,48 @@ impl Apply for Attributes {
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
mod tests {
use super::*;
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
use gloo::utils::document;
use js_sys::Reflect;
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

use super::*;

wasm_bindgen_test_configure!(run_in_browser);

fn create_element() -> (Element, BSubtree) {
let element = document().create_element("a").expect("failed to create element");
let element = document()
.create_element("a")
.expect("failed to create element");
let btree = BSubtree::create_root(&element);
(element, btree)
}

#[test]
fn properties_are_set() {
let attrs = Attributes::Static(&[
["href", "https://example.com/"],
["alt", "somewhere"],
]);
let attrs = Attributes::Static(&[["href", "https://example.com/"], ["alt", "somewhere"]]);
let (element, btree) = create_element();
attrs.apply(&btree, &element);
assert_eq!(
Reflect::get(element.as_ref(), &JsValue::from_str("href")).expect("no href").as_string().expect("not a string"),
Reflect::get(element.as_ref(), &JsValue::from_str("href"))
.expect("no href")
.as_string()
.expect("not a string"),
"https://example.com/",
"property `href` not set properly"
);
assert_eq!(
Reflect::get(element.as_ref(), &JsValue::from_str("alt")).expect("no alt").as_string().expect("not a string"),
Reflect::get(element.as_ref(), &JsValue::from_str("alt"))
.expect("no alt")
.as_string()
.expect("not a string"),
"somewhere",
"property `alt` not set properly"
);
}

#[test]
fn class_id_are_attrs() {
let attrs = Attributes::Static(&[
["id", "foo"],
["class", "thing"],
]);
let attrs = Attributes::Static(&[["id", "foo"], ["class", "thing"]]);
let (element, btree) = create_element();
attrs.apply(&btree, &element);
assert_eq!(element.get_attribute("id").unwrap(), "foo");
Expand Down
20 changes: 16 additions & 4 deletions packages/yew/src/dom_bundle/btag/mod.rs
Expand Up @@ -386,7 +386,7 @@ mod feat_hydration {
#[cfg(test)]
mod tests {
use gloo::utils::document;
use wasm_bindgen::JsCast;
use wasm_bindgen::{JsCast, JsValue};
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
use web_sys::HtmlInputElement as InputElement;

Expand Down Expand Up @@ -932,7 +932,7 @@ mod tests {
}

// test for bug: https://github.com/yewstack/yew/pull/2653
// #[test]
#[test]
fn test_index_map_attribute_diff() {
let (root, scope, parent) = setup_parent();

Expand Down Expand Up @@ -969,8 +969,20 @@ mod tests {
.dyn_ref::<web_sys::Element>()
.unwrap()
.outer_html(),
"<div tabindex=\"0\"></div>"
)
"<div></div>"
);

assert_eq!(
js_sys::Reflect::get(
test_ref.get().unwrap().as_ref(),
&JsValue::from_str("tabindex")
)
.expect("no tabindex")
.as_string()
.expect("not a string"),
"0",
"property `tabindex` not set properly"
);
}
}

Expand Down

0 comments on commit 866dbe6

Please sign in to comment.