Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
hamza1311 committed Aug 27, 2022
1 parent 04fef5e commit f9f1a7c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
11 changes: 6 additions & 5 deletions packages/yew/src/dom_bundle/braw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,18 @@ impl Reconcilable for VRaw {
#[cfg(test)]
mod tests {
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

use super::*;
use crate::virtual_dom::VNode;
use crate::dom_bundle::utils::setup_parent;
use crate::virtual_dom::VNode;

wasm_bindgen_test_configure!(run_in_browser);

#[test]
fn braw_works_one_node() {
let (root, scope, parent) = setup_parent();

const HTML: &str ="<span>text</span>";
const HTML: &str = "<span>text</span>";
let elem = VNode::from_raw_html(HTML.into());
let (_, mut elem) = elem.attach(&root, &scope, &parent, NodeRef::default());
assert_braw(&mut elem);
Expand All @@ -147,7 +148,7 @@ mod tests {
fn braw_works_no_node() {
let (root, scope, parent) = setup_parent();

const HTML: &str ="";
const HTML: &str = "";
let elem = VNode::from_raw_html(HTML.into());
let (_, mut elem) = elem.attach(&root, &scope, &parent, NodeRef::default());
assert_braw(&mut elem);
Expand All @@ -158,7 +159,7 @@ mod tests {
fn braw_works_one_node_nested() {
let (root, scope, parent) = setup_parent();

const HTML: &str =r#"<p>one <a href="https://yew.rs">link</a> more paragraph</p>"#;
const HTML: &str = r#"<p>one <a href="https://yew.rs">link</a> more paragraph</p>"#;
let elem = VNode::from_raw_html(HTML.into());
let (_, mut elem) = elem.attach(&root, &scope, &parent, NodeRef::default());
assert_braw(&mut elem);
Expand All @@ -168,7 +169,7 @@ mod tests {
fn braw_works_multi_top_nodes() {
let (root, scope, parent) = setup_parent();

const HTML: &str =r#"<p>paragraph</p><a href="https://yew.rs">link</a>"#;
const HTML: &str = r#"<p>paragraph</p><a href="https://yew.rs">link</a>"#;
let elem = VNode::from_raw_html(HTML.into());
let (_, mut elem) = elem.attach(&root, &scope, &parent, NodeRef::default());
assert_braw(&mut elem);
Expand Down
6 changes: 3 additions & 3 deletions packages/yew/src/virtual_dom/vraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ pub struct VRaw {

#[cfg(feature = "ssr")]
mod feat_ssr {
use super::*;
use html_parser::Dom;
use std::borrow::Cow;

use html_parser::Dom;

use super::*;
use crate::html::AnyScope;
use crate::platform::io::BufWriter;

Expand All @@ -22,7 +23,6 @@ mod feat_ssr {
_parent_scope: &AnyScope,
_hydratable: bool,
) {

// this is needed to ensure the resulting HTML during CSR and SSR is the same
let dom = Dom::parse(self.html.as_ref()).expect("invalid HTML was passed");
if dom.children.len() > 1 {
Expand Down
31 changes: 22 additions & 9 deletions packages/yew/tests/raw_html.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
mod common;


use yew::prelude::*;


#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::wasm_bindgen_test as test;
use yew::prelude::*;
#[cfg(target_arch = "wasm32")]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
#[cfg(feature = "tokio")]
Expand Down Expand Up @@ -34,9 +31,12 @@ macro_rules! create_test {
#[cfg(target_arch = "wasm32")]
{
use std::time::Duration;

use yew::platform::time::sleep;

yew::Renderer::<App>::with_root(gloo::utils::document().get_element_by_id("output").unwrap())
yew::Renderer::<App>::with_root(
gloo::utils::document().get_element_by_id("output").unwrap(),
)
.render();

// wait for render to finish
Expand All @@ -49,14 +49,27 @@ macro_rules! create_test {
}
#[cfg(not(target_arch = "wasm32"))]
{
let actual = yew::ServerRenderer::<App>::new() .hydratable(false).render().await;
assert_eq!(actual, format!(r#"<div id="raw-container">{}</div>"#, $expected));
let actual = yew::ServerRenderer::<App>::new()
.hydratable(false)
.render()
.await;
assert_eq!(
actual,
format!(r#"<div id="raw-container">{}</div>"#, $expected)
);
}
}
};
}

create_test!(empty_string, "");
create_test!(one_node, "<span>text</span>");
create_test!(one_but_nested_node, r#"<p>one <a href="https://yew.rs">link</a> more paragraph</p>"#);
create_test!(multi_node, r#"<p>paragraph</p><a href="https://yew.rs">link</a>"#, wrap_div);
create_test!(
one_but_nested_node,
r#"<p>one <a href="https://yew.rs">link</a> more paragraph</p>"#
);
create_test!(
multi_node,
r#"<p>paragraph</p><a href="https://yew.rs">link</a>"#,
wrap_div
);

0 comments on commit f9f1a7c

Please sign in to comment.