Skip to content

Commit

Permalink
Move tests (yewstack#897)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry authored Jan 26, 2020
1 parent d4868b0 commit 38f4054
Show file tree
Hide file tree
Showing 10 changed files with 581 additions and 562 deletions.
24 changes: 24 additions & 0 deletions src/format/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,27 @@ pub struct Json<T>(pub T);
text_format!(Json based on serde_json);

binary_format!(Json based on serde_json);

#[cfg(test)]
mod tests {
use super::*;
use crate::format::{Binary, Text};
use serde::{Deserialize, Serialize};
#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[test]
fn json_format() {
#[derive(Serialize, Deserialize)]
struct Data {
value: u8,
}

let Json(data): Json<Result<Data, _>> = Json::from(Ok(r#"{"value": 123}"#.to_string()));
let data = data.unwrap();
assert_eq!(data.value, 123);

let _stored: Text = Json(&data).into();
let _stored: Binary = Json(&data).into();
}
}
64 changes: 64 additions & 0 deletions src/virtual_dom/vcomp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,67 @@ impl<COMP: Component> fmt::Debug for VChild<COMP> {
f.write_str("VChild<_>")
}
}

#[cfg(test)]
mod tests {
use crate::macros::Properties;
use crate::{html, Component, ComponentLink, Html, ShouldRender};
#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

#[cfg(feature = "wasm_test")]
wasm_bindgen_test_configure!(run_in_browser);

struct Comp;

#[derive(Clone, PartialEq, Properties)]
struct Props {
field_1: u32,
field_2: u32,
}

impl Component for Comp {
type Message = ();
type Properties = Props;

fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self {
Comp
}

fn update(&mut self, _: Self::Message) -> ShouldRender {
unimplemented!();
}

fn view(&self) -> Html {
unimplemented!();
}
}

#[test]
fn set_properties_to_component() {
html! {
<Comp />
};

html! {
<Comp field_1=1 />
};

html! {
<Comp field_2=2 />
};

html! {
<Comp field_1=1 field_2=2 />
};

let props = Props {
field_1: 1,
field_2: 1,
};

html! {
<Comp with props />
};
}
}
42 changes: 42 additions & 0 deletions src/virtual_dom/vlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,45 @@ impl VDiff for VList {
previous_sibling
}
}

#[cfg(test)]
mod tests {
use crate::{html, Component, ComponentLink, Html, ShouldRender};
#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

#[cfg(feature = "wasm_test")]
wasm_bindgen_test_configure!(run_in_browser);

struct Comp;

impl Component for Comp {
type Message = ();
type Properties = ();

fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self {
Comp
}

fn update(&mut self, _: Self::Message) -> ShouldRender {
unimplemented!();
}

fn view(&self) -> Html {
unimplemented!();
}
}

#[test]
fn check_fragments() {
let fragment = html! {
<>
</>
};
html! {
<div>
{ fragment }
</div>
};
}
}
Loading

0 comments on commit 38f4054

Please sign in to comment.