wasm-bindgen/crates/web-sys/tests/wasm/headers.rs
Alex Crichton 4282ec25bd Move web-sys tests to the new test framework
Migrate most `web-sys` tests to the new `wasm_bindgen_test` framework with the
new headless browser capabilities!
2018-07-30 11:07:07 -07:00

32 lines
959 B
Rust

use wasm_bindgen_test::*;
use wasm_bindgen::prelude::*;
use web_sys::Headers;
#[wasm_bindgen(module = "./tests/wasm/headers.js")]
extern {
fn new_headers() -> Headers;
}
#[wasm_bindgen_test]
fn headers() {
let headers = new_headers();
assert_eq!(headers.get("foo").unwrap(), None);
assert_eq!(
headers.get("content-type").unwrap(),
Some("text/plain".to_string()),
);
assert_eq!(
headers.get("Content-Type").unwrap(),
Some("text/plain".to_string()),
);
assert!(headers.get("").is_err());
assert!(headers.set("", "").is_err());
assert!(headers.set("x", "").is_ok());
assert_eq!(headers.get("x").unwrap(), Some(String::new()));
assert!(headers.delete("x").is_ok());
assert_eq!(headers.get("x").unwrap(), None);
assert!(headers.append("a", "y").is_ok());
assert!(headers.append("a", "z").is_ok());
assert_eq!(headers.get("a").unwrap(), Some("y, z".to_string()));
}