Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const ChristmasMovies = require("./02. Christmas Movies_Resources");
- const { beforeEach } = require("mocha");
- const { expect } = require("chai");
- describe("ChirstmasMovies tests", function() {
- let movies;
- beforeEach(function() {
- movies = new ChristmasMovies();
- });
- describe("constructor test", function() {
- it("should intialize property correctly", function() {
- expect(movies.movieCollection).to.deep.equal([]);
- expect(movies.watched).to.deep.equal({});
- expect(movies.actors).to.deep.equal([]);
- });
- });
- describe("buyMovie test", function() {
- it("should push correctly", function() {
- let expectedObj = {
- name: "Home Alone",
- actors: ["Macaulay Culkin", "Joe Pesci", "Daniel Stern"]
- };
- let outputMsg = movies.buyMovie("Home Alone", [
- "Macaulay Culkin",
- "Joe Pesci",
- "Daniel Stern"
- ]);
- expect(movies.movieCollection.length).to.equal(1);
- expect(movies.movieCollection[0]).to.deep.equal(expectedObj);
- expect(outputMsg).to.equal(
- "You just got Home Alone to your collection in which Macaulay Culkin, Joe Pesci, Daniel Stern are taking part!"
- );
- });
- it("should throw error", function() {
- movies.buyMovie("Home Alone", [
- "Macaulay Culkin",
- "Joe Pesci",
- "Daniel Stern"
- ]);
- let outputMsg = () =>
- movies.buyMovie("Home Alone", [
- "Macaulay Culkin",
- "Joe Pesci",
- "Daniel Stern"
- ]);
- expect(outputMsg).to.throw(
- Error,
- "You already own Home Alone in your collection!"
- );
- });
- });
- describe("discardMovie", function() {
- it("should throw error", function() {
- movies.buyMovie("Home Alone", [
- "Macaulay Culkin",
- "Joe Pesci",
- "Daniel Stern"
- ]);
- movies.buyMovie("Terminator", ["Arnold"]);
- let outputMsg = () => movies.discardMovie("American Gangster");
- expect(outputMsg).to.throw(
- Error,
- "American Gangster is not at your collection!"
- );
- });
- it("should throw error", function() {
- movies.buyMovie("Home Alone 2", ["Macaulay Culkin"]);
- movies.buyMovie("Terminator", ["Arnold"]);
- let msg = () => movies.discardMovie("Home Alone 2");
- expect(msg).to.throw(Error, "Home Alone 2 is not watched!");
- let output = movies.discardMovie(["Arnold"]);
- expect(output).to.equal("You just threw away Terminator!");
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement