Skip to content

Commit

Permalink
ApiImplForWasmのテストコードを加筆
Browse files Browse the repository at this point in the history
panicすることを確かめるのではなく、エラーメッセージを検証するように変更
  • Loading branch information
YuukiToriyama committed Nov 23, 2023
1 parent 9bbc7bb commit e314369
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/api/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,14 @@ mod api_tests {
}

#[wasm_bindgen_test]
#[should_panic]
async fn get_prefecture_master_fail() {
let api = ApiImplForWasm {};
api.get_prefecture_master("大阪都").await.unwrap();
let result = api.get_prefecture_master("大阪都").await;
assert!(result.is_err());
assert_eq!(
result.err().unwrap().error_message,
"https://yuukitoriyama.github.io/geolonia-japanese-addresses-accompanist/大阪都/master.jsonを取得できませんでした".to_string()
)
}

#[wasm_bindgen_test]
Expand All @@ -112,9 +116,13 @@ mod api_tests {
}

#[wasm_bindgen_test]
#[should_panic]
async fn get_city_master_fail() {
let api = ApiImplForWasm {};
api.get_city_master("石川県", "敦賀市").await.unwrap();
let result = api.get_city_master("石川県", "敦賀市").await;
assert!(result.is_err());
assert_eq!(
result.err().unwrap().error_message,
"https://geolonia.github.io/japanese-addresses/api/ja/石川県/敦賀市.jsonを取得できませんでした".to_string()
);
}
}

0 comments on commit e314369

Please sign in to comment.