victoriaSD

Unit Testing - 03. planYourTrip

Jun 11th, 2024
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. describe("Trip tests", () => {
  2. it("choosingDestination", () => {
  3. expect(() => {
  4. planYourTrip.choosingDestination("Ski Resort", "Winter", 2023);
  5. }).to.throw("Invalid Year!");
  6. expect(() => {
  7. planYourTrip.choosingDestination("Ski Resort", "Winter", null);
  8. }).to.throw("Invalid Year!");
  9. expect(() => {
  10. planYourTrip.choosingDestination("Ski Resort", "Winter", undefined);
  11. }).to.throw("Invalid Year!");
  12. expect(() => {
  13. planYourTrip.choosingDestination("Ski Resort", "Winter", "ham");
  14. }).to.throw("Invalid Year!");
  15. expect(() => {
  16. planYourTrip.choosingDestination("Paris", "Winter", 2024);
  17. }).to.throw("This destination is not what you are looking for.");
  18. expect(() => {
  19. planYourTrip.choosingDestination(20, "Winter", 2024);
  20. }).to.throw("This destination is not what you are looking for.");
  21. expect(
  22. planYourTrip.choosingDestination("Ski Resort", "Spring", 2024)
  23. ).to.equal(
  24. "Consider visiting during the Winter for the best experience at the Ski Resort."
  25. );
  26. expect(
  27. planYourTrip.choosingDestination("Ski Resort", "Winter", 2024)
  28. ).to.equal(
  29. "Great choice! The Winter is the perfect time to visit the Ski Resort."
  30. );
  31. });
  32.  
  33. it("exploreOptions", () => {
  34. expect(() => {
  35. planYourTrip.exploreOptions("Skiing", 0);
  36. }).to.throw("Invalid Information!");
  37. expect(() => {
  38. planYourTrip.exploreOptions(["Skiing"], "a");
  39. }).to.throw("Invalid Information!");
  40. expect(() => {
  41. planYourTrip.exploreOptions(["Skiing"], 1);
  42. }).to.throw("Invalid Information!");
  43. expect(() => {
  44. planYourTrip.exploreOptions(["Skiing"], 1.1);
  45. }).to.throw("Invalid Information!");
  46. expect(() => {
  47. planYourTrip.exploreOptions(["Skiing"], -1);
  48. }).to.throw("Invalid Information!");
  49. expect(planYourTrip.exploreOptions(["Skiing"], 0)).to.equal("");
  50. expect(planYourTrip.exploreOptions(["Skiing", "Kissing"], 0)).to.equal(
  51. "Kissing"
  52. );
  53. });
  54.  
  55. it("estimateExpenses", () => {
  56. expect(() => {
  57. planYourTrip.estimateExpenses("1", "1");
  58. }).to.throw("Invalid Information!");
  59. expect(() => {
  60. planYourTrip.estimateExpenses(1, "1");
  61. }).to.throw("Invalid Information!");
  62. expect(() => {
  63. planYourTrip.estimateExpenses("1", 1);
  64. }).to.throw("Invalid Information!");
  65. expect(() => {
  66. planYourTrip.estimateExpenses(1, 0);
  67. }).to.throw("Invalid Information!");
  68. expect(() => {
  69. planYourTrip.estimateExpenses(1, -1);
  70. }).to.throw("Invalid Information!");
  71. expect(planYourTrip.estimateExpenses(100, 1.2)).to.equal(
  72. "The trip is budget-friendly, estimated cost is $120.00."
  73. );
  74. expect(planYourTrip.estimateExpenses(100, 5)).to.equal(
  75. "The trip is budget-friendly, estimated cost is $500.00."
  76. );
  77. expect(planYourTrip.estimateExpenses(100, 7)).to.equal(
  78. "The estimated cost for the trip is $700.00, plan accordingly."
  79. );
  80. });
  81. });
  82.  
Advertisement
Add Comment
Please, Sign In to add comment