Skip to content

Commit 1b4776a

Browse files
committed
Fix test
1 parent 76d598a commit 1b4776a

File tree

3 files changed

+48
-50
lines changed

3 files changed

+48
-50
lines changed

bindings/devup-ui-wasm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
"types": "./pkg/index.d.ts",
2626
"scripts": {
2727
"build": "wasm-pack build --target nodejs --out-dir ./pkg --out-name index",
28-
"test": "cargo test"
28+
"test": "wasm-pack test --node"
2929
}
3030
}

bindings/devup-ui-wasm/src/lib.rs

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub fn code_extract(
106106
Err(error) => Err(JsValue::from_str(error.to_string().as_str())),
107107
}
108108
}
109-
fn object_to_typography(obj: Object, level: u8) -> Result<Typography, JsValue> {
109+
pub fn object_to_typography(obj: Object, level: u8) -> Result<Typography, JsValue> {
110110
Ok(Typography::new(
111111
Reflect::get(&obj, &JsValue::from_str("fontFamily"))?
112112
.as_string()
@@ -260,51 +260,3 @@ pub fn get_theme_interface(
260260
))
261261
}
262262
}
263-
264-
#[cfg(test)]
265-
mod tests {
266-
use super::*;
267-
use wasm_bindgen_test::*;
268-
269-
#[wasm_bindgen_test]
270-
fn test_object_to_typography() {
271-
let obj = Object::new();
272-
Reflect::set(
273-
&obj,
274-
&JsValue::from_str("fontFamily"),
275-
&JsValue::from_str("Arial"),
276-
)
277-
.unwrap();
278-
Reflect::set(
279-
&obj,
280-
&JsValue::from_str("fontSize"),
281-
&JsValue::from_str("12px"),
282-
)
283-
.unwrap();
284-
Reflect::set(
285-
&obj,
286-
&JsValue::from_str("fontWeight"),
287-
&JsValue::from_str("bold"),
288-
)
289-
.unwrap();
290-
Reflect::set(
291-
&obj,
292-
&JsValue::from_str("lineHeight"),
293-
&JsValue::from_str("1.5"),
294-
)
295-
.unwrap();
296-
Reflect::set(
297-
&obj,
298-
&JsValue::from_str("letterSpacing"),
299-
&JsValue::from_str("1px"),
300-
)
301-
.unwrap();
302-
let typography = object_to_typography(obj, 0).unwrap();
303-
assert_eq!(typography.font_family, "Arial");
304-
assert_eq!(typography.font_size, "12px");
305-
assert_eq!(typography.font_weight, "bold");
306-
assert_eq!(typography.line_height, "1.5");
307-
assert_eq!(typography.letter_spacing, "1px");
308-
assert_eq!(typography.level, 0);
309-
}
310-
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use devup_ui_wasm::object_to_typography;
2+
use js_sys::{Object, Reflect};
3+
use wasm_bindgen::JsValue;
4+
use wasm_bindgen_test::*;
5+
6+
#[wasm_bindgen_test]
7+
fn test_object_to_typography() {
8+
let obj = Object::new();
9+
Reflect::set(
10+
&obj,
11+
&JsValue::from_str("fontFamily"),
12+
&JsValue::from_str("Arial"),
13+
)
14+
.unwrap();
15+
Reflect::set(
16+
&obj,
17+
&JsValue::from_str("fontSize"),
18+
&JsValue::from_str("12px"),
19+
)
20+
.unwrap();
21+
Reflect::set(
22+
&obj,
23+
&JsValue::from_str("fontWeight"),
24+
&JsValue::from_str("bold"),
25+
)
26+
.unwrap();
27+
Reflect::set(
28+
&obj,
29+
&JsValue::from_str("lineHeight"),
30+
&JsValue::from_str("1.5"),
31+
)
32+
.unwrap();
33+
Reflect::set(
34+
&obj,
35+
&JsValue::from_str("letterSpacing"),
36+
&JsValue::from_str("1px"),
37+
)
38+
.unwrap();
39+
let typography = object_to_typography(obj, 0).unwrap();
40+
assert_eq!(typography.font_family, "Arial");
41+
assert_eq!(typography.font_size, "12px");
42+
assert_eq!(typography.font_weight, "bold");
43+
assert_eq!(typography.line_height, "1.5");
44+
assert_eq!(typography.letter_spacing, "1px");
45+
assert_eq!(typography.level, 0);
46+
}

0 commit comments

Comments
 (0)