options_collection.rs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. use wasm_bindgen::prelude::*;
  2. use wasm_bindgen_test::*;
  3. use web_sys::HtmlOptionsCollection;
  4. #[wasm_bindgen(module = "/tests/wasm/element.js")]
  5. extern "C" {
  6. fn new_food_options_collection() -> HtmlOptionsCollection;
  7. }
  8. #[wasm_bindgen_test]
  9. fn test_options_collection() {
  10. let opt_collection = new_food_options_collection();
  11. assert!(
  12. opt_collection.length() == 4,
  13. "Our option collection should have four options."
  14. );
  15. assert!(
  16. opt_collection.remove(0).is_ok(),
  17. "We should be able to successfully remove an element from an option collection."
  18. );
  19. assert!(
  20. opt_collection.length() == 3,
  21. "Our option collection should have three options after removing one."
  22. );
  23. assert!(
  24. opt_collection.set_selected_index(1).is_ok(),
  25. "Should be able to set the selected index of an option collection if it is valid."
  26. );
  27. assert_eq!(
  28. opt_collection.selected_index().unwrap(),
  29. 1,
  30. "The second option should be selected in our option collection."
  31. );
  32. opt_collection.set_length(1234);
  33. assert_eq!(
  34. opt_collection.length(),
  35. 1234,
  36. "Our option collections length should update after being set to 1234."
  37. );
  38. }