Skip to content

Commit 59d4750

Browse files
Add tests
1 parent 3dc6439 commit 59d4750

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

tests/wasm/js_objects.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ exports.js_another_vector_return = () => {
8383
assert.deepStrictEqual(wasm.another_vector_return_get_array(), [1, 2, 3, 4, 5, 6]);
8484
};
8585

86+
exports.returning_vector_string_foo = () => {
87+
return "This is the mostest awesomest string that can possibly exist.";
88+
};
89+
90+
exports.js_returning_vector_string = () => {
91+
assert.strictEqual(wasm.returning_vector_string_bar().length, 10);
92+
};
93+
94+
exports.js_another_vector_string_return = () => {
95+
assert.deepStrictEqual(wasm.another_vector_string_return_get_array(), ["1", "2", "3", "4", "5", "6"]);
96+
};
97+
8698
exports.verify_serde = function(a) {
8799
assert.deepStrictEqual(a, {
88100
a: 0,

tests/wasm/js_objects.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use js_sys::JsString;
12
use wasm_bindgen::prelude::*;
23
use wasm_bindgen_test::*;
34

@@ -24,8 +25,12 @@ extern "C" {
2425

2526
fn returning_vector_foo() -> JsValue;
2627
fn js_returning_vector();
27-
2828
fn js_another_vector_return();
29+
30+
fn returning_vector_string_foo() -> JsString;
31+
fn js_returning_vector_string();
32+
fn js_another_vector_string_return();
33+
2934
fn verify_serde(val: JsValue) -> JsValue;
3035
}
3136

@@ -107,6 +112,37 @@ fn another_vector_return() {
107112
js_another_vector_return();
108113
}
109114

115+
#[wasm_bindgen]
116+
pub fn returning_vector_string_bar() -> Vec<JsString> {
117+
let mut res = Vec::new();
118+
for _ in 0..10 {
119+
res.push(returning_vector_string_foo())
120+
}
121+
res
122+
}
123+
124+
#[wasm_bindgen_test]
125+
fn returning_vector_string() {
126+
js_returning_vector_string();
127+
}
128+
129+
#[wasm_bindgen]
130+
pub fn another_vector_string_return_get_array() -> Vec<JsString> {
131+
vec![
132+
"1".into(),
133+
"2".into(),
134+
"3".into(),
135+
"4".into(),
136+
"5".into(),
137+
"6".into(),
138+
]
139+
}
140+
141+
#[wasm_bindgen_test]
142+
fn another_vector_string_return() {
143+
js_another_vector_string_return();
144+
}
145+
110146
#[cfg(feature = "serde-serialize")]
111147
#[wasm_bindgen_test]
112148
fn serde() {

0 commit comments

Comments
 (0)