1
0
mirror of https://github.com/fluencelabs/wasm-bindgen synced 2025-06-27 03:31:35 +00:00
Files
.cargo
benchmarks
ci
crates
anyref-xform
backend
cli
cli-support
futures
js-sys
macro
macro-support
shared
test
test-macro
threads-xform
typescript
typescript-tests
wasm-interpreter
web-sys
src
tests
wasm
anchor_element.rs
body_element.rs
br_element.rs
button_element.rs
console.rs
div_element.rs
dom_point.rs
element.js
element.rs
event.js
event.rs
head_element.rs
headers.js
headers.rs
heading_element.rs
history.rs
hr_element.rs
html_element.rs
html_html_element.rs
indexeddb.rs
input_element.rs
location.rs
main.rs
menu_element.rs
menu_item_element.rs
meta_element.rs
meter_element.rs
mod_elements.rs
olist_element.rs
optgroup_element.rs
option_element.rs
options_collection.rs
output_element.rs
paragraph_element.rs
param_element.rs
performance.rs
pre_element.rs
progress_element.rs
quote_element.rs
response.js
response.rs
rtc_rtp_transceiver_direction.rs
script_element.rs
select_element.rs
slot_element.rs
span_element.rs
style_element.rs
table_element.rs
title_element.rs
whitelisted_immutable_slices.rs
xpath_result.rs
webidls
Cargo.toml
README.md
build.rs
webidl
webidl-tests
examples
guide
releases
src
tests
.gitattributes
.gitignore
CHANGELOG.md
CONTRIBUTING.md
Cargo.toml
LICENSE-APACHE
LICENSE-MIT
README.md
_package.json
azure-pipelines.yml
build.rs
publish.rs
wasm-bindgen/crates/web-sys/tests/wasm/script_element.rs

81 lines
2.4 KiB
Rust
Raw Normal View History

use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;
use web_sys::HtmlScriptElement;
2019-02-26 08:33:14 -08:00
#[wasm_bindgen(module = "/tests/wasm/element.js")]
extern "C" {
fn new_script() -> HtmlScriptElement;
}
#[wasm_bindgen_test]
fn test_script_element() {
let element = new_script();
assert_eq!(element.src(), "", "Shouldn't have a src");
element.set_src("https://example.com/script.js");
assert_eq!(
element.src(),
"https://example.com/script.js",
"Should have a src"
);
assert_eq!(element.type_(), "", "Shouldn't have a type");
element.set_type("application/javascript");
assert_eq!(
element.type_(),
"application/javascript",
"Should have a type"
);
assert!(!element.no_module(), "Shouldn't be a nomodule");
element.set_no_module(true);
assert!(element.no_module(), "Should be a nomodule");
assert_eq!(element.charset(), "", "Shouldn't have a charset");
element.set_charset("UTF-8");
assert_eq!(element.charset(), "UTF-8", "Should have a charset");
assert!(element.r#async(), "Should be async");
element.set_async(false);
assert!(!element.r#async(), "Shouldn't be a async");
assert!(!element.defer(), "Shouldn't be a defer");
element.set_defer(true);
assert!(element.defer(), "Should be a defer");
assert!(
element.cross_origin().is_none(),
"Shouldn't have a crossorigin"
);
element.set_cross_origin(Some("anonymous"));
assert_eq!(
element.cross_origin().unwrap(),
"anonymous",
"Should have a crossorigin"
);
element.set_cross_origin(None);
assert!(
element.cross_origin().is_none(),
"Shouldn't have a crossorigin"
);
assert_eq!(element.text().unwrap(), "", "Shouldn't have text");
assert_eq!(element.set_text("text").unwrap(), ());
assert_eq!(element.text().unwrap(), "text", "Should have text");
assert_eq!(element.event(), "", "Shouldn't have an event");
element.set_event("ev");
assert_eq!(element.event(), "ev", "Should have an event");
assert_eq!(element.html_for(), "", "Shouldn't have an html_for");
element.set_html_for("hey");
assert_eq!(element.html_for(), "hey", "Should have an html_for");
assert_eq!(element.integrity(), "", "Shouldn't have an integrity");
element.set_integrity("integrity-val");
assert_eq!(
element.integrity(),
"integrity-val",
"Should have an integrity"
);
}