1 use wasm_bindgen::prelude::*;
2 use wasm_bindgen_test::*;
3 use web_sys::HtmlOutputElement;
4 
5 #[wasm_bindgen(module = "/tests/wasm/element.js")]
6 extern "C" {
new_output() -> HtmlOutputElement7     fn new_output() -> HtmlOutputElement;
8 }
9 
10 #[wasm_bindgen_test]
test_output_element()11 fn test_output_element() {
12     let output = new_output();
13     assert!(
14         output.html_for().length() == 0,
15         "Our basic <output> should have no html associated with it."
16     );
17     assert!(
18         output.form().is_none(),
19         "Our basic <output> should have no form associated with it."
20     );
21 
22     output.set_name("Calculation result");
23     assert_eq!(
24         output.name(),
25         "Calculation result",
26         "Output name should be 'Calculation result'."
27     );
28 
29     assert_eq!(
30         output.type_(),
31         "output",
32         "Our basic <output> should have an type of 'output'."
33     );
34 
35     output.set_default_value("27");
36     assert_eq!(
37         output.default_value(),
38         "27",
39         "Default output value should be '27'."
40     );
41 
42     output.set_value("49");
43     assert_eq!(output.value(), "49", "Output value should be '49'.");
44 
45     // TODO: Fails in Chrome, but not in Firefox.
46     //assert!(output.will_validate(), "Output should validate by default (maybe browser dependent?)");
47 
48     assert!(
49         output.validity().valid(),
50         "Our <output>s validity should be true."
51     );
52 
53     assert!(
54         output.validation_message().is_ok(),
55         "We should be able to retrieve some validation message from our <output>."
56     );
57 
58     assert!(output.check_validity(), "Our <output> should be valid.");
59 
60     assert!(
61         output.report_validity(),
62         "Our <output> should report valid."
63     );
64 
65     output.set_custom_validity("Some scary error message.");
66 
67     assert!(
68         output.labels().length() == 0,
69         "Our basic <output> shouldn't have any labels associated with it."
70     );
71 }
72