1 use wasm_bindgen::prelude::*;
2 use wasm_bindgen_test::*;
3 use web_sys::HtmlScriptElement;
4 
5 #[wasm_bindgen(module = "/tests/wasm/element.js")]
6 extern "C" {
new_script() -> HtmlScriptElement7     fn new_script() -> HtmlScriptElement;
8 }
9 
10 #[wasm_bindgen_test]
test_script_element()11 fn test_script_element() {
12     let element = new_script();
13     assert_eq!(element.src(), "", "Shouldn't have a src");
14     element.set_src("https://example.com/script.js");
15     assert_eq!(
16         element.src(),
17         "https://example.com/script.js",
18         "Should have a src"
19     );
20 
21     assert_eq!(element.type_(), "", "Shouldn't have a type");
22     element.set_type("application/javascript");
23     assert_eq!(
24         element.type_(),
25         "application/javascript",
26         "Should have a type"
27     );
28 
29     assert!(!element.no_module(), "Shouldn't be a nomodule");
30     element.set_no_module(true);
31     assert!(element.no_module(), "Should be a nomodule");
32 
33     assert_eq!(element.charset(), "", "Shouldn't have a charset");
34     element.set_charset("UTF-8");
35     assert_eq!(element.charset(), "UTF-8", "Should have a charset");
36 
37     assert!(element.r#async(), "Should be async");
38     element.set_async(false);
39     assert!(!element.r#async(), "Shouldn't be a async");
40 
41     assert!(!element.defer(), "Shouldn't be a defer");
42     element.set_defer(true);
43     assert!(element.defer(), "Should be a defer");
44 
45     assert!(
46         element.cross_origin().is_none(),
47         "Shouldn't have a crossorigin"
48     );
49     element.set_cross_origin(Some("anonymous"));
50     assert_eq!(
51         element.cross_origin().unwrap(),
52         "anonymous",
53         "Should have a crossorigin"
54     );
55     element.set_cross_origin(None);
56     assert!(
57         element.cross_origin().is_none(),
58         "Shouldn't have a crossorigin"
59     );
60 
61     assert_eq!(element.text().unwrap(), "", "Shouldn't have text");
62     assert_eq!(element.set_text("text").unwrap(), ());
63     assert_eq!(element.text().unwrap(), "text", "Should have text");
64 
65     assert_eq!(element.event(), "", "Shouldn't have an event");
66     element.set_event("ev");
67     assert_eq!(element.event(), "ev", "Should have an event");
68 
69     assert_eq!(element.html_for(), "", "Shouldn't have an html_for");
70     element.set_html_for("hey");
71     assert_eq!(element.html_for(), "hey", "Should have an html_for");
72 
73     assert_eq!(element.integrity(), "", "Shouldn't have an integrity");
74     element.set_integrity("integrity-val");
75     assert_eq!(
76         element.integrity(),
77         "integrity-val",
78         "Should have an integrity"
79     );
80 }
81