wasm-bindgen/crates/web-sys/tests/wasm/event.rs
Alex Crichton 7ecf4aae87 cargo +nightly fmt --all
Rustfmt all the things!
2018-09-26 08:26:00 -07:00

33 lines
995 B
Rust

use futures::future::Future;
use js_sys::{Object, Promise};
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::JsFuture;
use wasm_bindgen_test::*;
use web_sys::Event;
#[wasm_bindgen(module = "./tests/wasm/event.js")]
extern "C" {
fn new_event() -> Promise;
}
#[wasm_bindgen_test(async)]
fn event() -> impl Future<Item = (), Error = JsValue> {
JsFuture::from(new_event()).map(Event::from).map(|event| {
// All DOM interfaces should inherit from `Object`.
assert!(event.is_instance_of::<Object>());
let _: &Object = event.as_ref();
// These should match `new Event`.
assert!(event.bubbles());
assert!(event.cancelable());
assert!(event.composed());
// The default behavior not initially prevented, but after
// we call `prevent_default` it better be.
assert!(!event.default_prevented());
event.prevent_default();
assert!(event.default_prevented());
})
}