summaryrefslogtreecommitdiffstats
path: root/vendor/js-sys/tests/wasm/EvalError.rs
blob: 52abe06ca36ecb8e04efdb0701ad1cf58c1e4ccf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use js_sys::*;
use wasm_bindgen::JsCast;
use wasm_bindgen::JsValue;
use wasm_bindgen_test::*;

// Note: This error is not thrown any more, so there are no tests that will generate this error.
// Instead we just have to manually construct it

#[wasm_bindgen_test]
fn new() {
    let error = EvalError::new("some message");
    let base_error: &Error = error.dyn_ref().unwrap();
    assert_eq!(JsValue::from(base_error.message()), "some message");
}

#[wasm_bindgen_test]
fn set_message() {
    let error = EvalError::new("test");
    let base_error: &Error = error.dyn_ref().unwrap();
    base_error.set_message("another");
    assert_eq!(JsValue::from(base_error.message()), "another");
}

#[wasm_bindgen_test]
fn name() {
    let error = EvalError::new("test");
    let base_error: &Error = error.dyn_ref().unwrap();
    assert_eq!(JsValue::from(base_error.name()), "EvalError");
}

#[wasm_bindgen_test]
fn set_name() {
    let error = EvalError::new("test");
    let base_error: &Error = error.dyn_ref().unwrap();
    base_error.set_name("different");
    assert_eq!(JsValue::from(base_error.name()), "different");
}

#[wasm_bindgen_test]
fn to_string() {
    let error = EvalError::new("error message 1");
    let base_error: &Error = error.dyn_ref().unwrap();
    assert_eq!(
        JsValue::from(base_error.to_string()),
        "EvalError: error message 1"
    );
    base_error.set_name("error_name_1");
    assert_eq!(
        JsValue::from(base_error.to_string()),
        "error_name_1: error message 1"
    );
}

#[wasm_bindgen_test]
fn evalerror_inheritance() {
    let error = EvalError::new("some message");
    assert!(error.is_instance_of::<EvalError>());
    assert!(error.is_instance_of::<Error>());
    assert!(error.is_instance_of::<Object>());
    let _: &Error = error.as_ref();
    let _: &Object = error.as_ref();
}