Skip to content

Commit

Permalink
fix: various issues in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
coroiu committed Nov 12, 2024
1 parent 159f87b commit 1ef0bfe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions crates/bitwarden-error/tests/flat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ fn variant_names_for_enum() {
#[allow(dead_code)]
#[derive(Debug)]
#[bitwarden_error(flat)]
enum SimpleError {
enum SimpleEnum {
Foo,
Bar,
Baz,
}
impl Display for SimpleError {
impl Display for SimpleEnum {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "This is an error")
}
Expand All @@ -88,22 +88,22 @@ fn converts_to_js_error() {
use wasm_bindgen::JsValue;

#[derive(Debug, FlatError)]
enum SomeError {
enum FlatEnum {
Foo,
Bar,
Baz,
}
impl Display for SomeError {
impl Display for FlatEnum {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "This is an error")
}
}

let simple = SomeError::Baz;
let simple = FlatEnum::Baz;
let js_value: JsValue = simple.into();

let js_error = SdkJsError::from(js_value);
assert_eq!(js_error.name(), "SomeError");
assert_eq!(js_error.name(), "FlatEnum");
assert_eq!(js_error.message(), "This is an error");
assert_eq!(js_error.variant(), "Baz");
}
4 changes: 2 additions & 2 deletions crates/bitwarden-error/tests/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ fn converts_to_js() {

// Errors only natively support rust -> js and so we use Reflect to get the value straight from
// the JSValue
let value = js_sys::Reflect::get(&js_value, &JsValue::from("Baz")).unwrap();
assert_eq!(value.as_string().unwrap(), "This is an error");
let value = js_sys::Reflect::get(&js_value, &JsValue::from("Baz")).unwrap_or(JsValue::NULL);
assert_eq!(value.as_string().unwrap_or_default(), "This is an error");
}

0 comments on commit 1ef0bfe

Please sign in to comment.