Advertisement
HariNikolov

Untitled

Dec 10th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. const ChristmasMovies = require("./02. Christmas Movies_Resources");
  2. const { beforeEach } = require("mocha");
  3. const { expect } = require("chai");
  4.  
  5. describe("ChirstmasMovies tests", function() {
  6. let movies;
  7. beforeEach(function() {
  8. movies = new ChristmasMovies();
  9. });
  10. describe("constructor test", function() {
  11. it("should intialize property correctly", function() {
  12. expect(movies.movieCollection).to.deep.equal([]);
  13. expect(movies.watched).to.deep.equal({});
  14. expect(movies.actors).to.deep.equal([]);
  15. });
  16. });
  17. describe("buyMovie test", function() {
  18. it("should push correctly", function() {
  19. let expectedObj = {
  20. name: "Home Alone",
  21. actors: ["Macaulay Culkin", "Joe Pesci", "Daniel Stern"]
  22. };
  23. let outputMsg = movies.buyMovie("Home Alone", [
  24. "Macaulay Culkin",
  25. "Joe Pesci",
  26. "Daniel Stern"
  27. ]);
  28. expect(movies.movieCollection.length).to.equal(1);
  29. expect(movies.movieCollection[0]).to.deep.equal(expectedObj);
  30. expect(outputMsg).to.equal(
  31. "You just got Home Alone to your collection in which Macaulay Culkin, Joe Pesci, Daniel Stern are taking part!"
  32. );
  33. });
  34. it("should throw error", function() {
  35. movies.buyMovie("Home Alone", [
  36. "Macaulay Culkin",
  37. "Joe Pesci",
  38. "Daniel Stern"
  39. ]);
  40. let outputMsg = () =>
  41. movies.buyMovie("Home Alone", [
  42. "Macaulay Culkin",
  43. "Joe Pesci",
  44. "Daniel Stern"
  45. ]);
  46. expect(outputMsg).to.throw(
  47. Error,
  48. "You already own Home Alone in your collection!"
  49. );
  50. });
  51. });
  52. describe("discardMovie", function() {
  53. it("should throw error", function() {
  54. movies.buyMovie("Home Alone", [
  55. "Macaulay Culkin",
  56. "Joe Pesci",
  57. "Daniel Stern"
  58. ]);
  59. movies.buyMovie("Terminator", ["Arnold"]);
  60. let outputMsg = () => movies.discardMovie("American Gangster");
  61. expect(outputMsg).to.throw(
  62. Error,
  63. "American Gangster is not at your collection!"
  64. );
  65. });
  66. it("should throw error", function() {
  67. movies.buyMovie("Home Alone 2", ["Macaulay Culkin"]);
  68. movies.buyMovie("Terminator", ["Arnold"]);
  69. let msg = () => movies.discardMovie("Home Alone 2");
  70. expect(msg).to.throw(Error, "Home Alone 2 is not watched!");
  71. let output = movies.discardMovie(["Arnold"]);
  72. expect(output).to.equal("You just threw away Terminator!");
  73. });
  74. });
  75. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement