From f59fd6fc93452e104f779e46b9a6548b6c7c7d4b Mon Sep 17 00:00:00 2001 From: Logan Thirion Date: Thu, 19 Nov 2020 09:23:24 -0600 Subject: [PATCH 1/2] changed doHomework tests to not require modifing the object reference and be more functional. --- test/student.test.js | 211 +++++++++++++++++++++++-------------------- 1 file changed, 114 insertions(+), 97 deletions(-) diff --git a/test/student.test.js b/test/student.test.js index f5191e1..a32733c 100644 --- a/test/student.test.js +++ b/test/student.test.js @@ -1,138 +1,155 @@ -const expect = require('chai').expect -const Student = require('../src').Student +const expect = require("chai").expect; +const Student = require("../src").Student; -describe('Student', function () { +describe("Student", function () { before(function () { - this.properties = [ 'Shelly Vasquez', 44 ] - }) + this.properties = ["Shelly Vasquez", 44]; + }); - describe('new Student()', function () { - it('should accept the following arguments: name, skillLevel', function () { - const student = new Student(...this.properties) + describe("new Student()", function () { + it("should accept the following arguments: name, skillLevel", function () { + const student = new Student(...this.properties); - expect(student).to.be.an.instanceof(Student) - }) + expect(student).to.be.an.instanceof(Student); + }); - it('should have properties by the same name', function () { - const student = new Student(...this.properties) - const [ name, skillLevel ] = this.properties + it("should have properties by the same name", function () { + const student = new Student(...this.properties); + const [name, skillLevel] = this.properties; - expect(student.name).to.equal(name) - expect(student.skillLevel).to.equal(skillLevel) - }) + expect(student.name).to.equal(name); + expect(student.skillLevel).to.equal(skillLevel); + }); - it('should have a property of `assignments` which defaults to an empty array', function () { - const student = new Student(...this.properties) + it("should have a property of `assignments` which defaults to an empty array", function () { + const student = new Student(...this.properties); - expect(student.assignments).to.deep.equal([]) - }) - }) + expect(student.assignments).to.deep.equal([]); + }); + }); - describe('.study()', function () { - it('should increase the student\'s `skillLevel` by 1', function () { - const student = new Student(...this.properties) - student.study() + describe(".study()", function () { + it("should increase the student's `skillLevel` by 1", function () { + const student = new Student(...this.properties); + student.study(); - expect(student.skillLevel).to.equal(this.properties[1] + 1) - }) + expect(student.skillLevel).to.equal(this.properties[1] + 1); + }); - it('should cannot increase the student\'s `skillLevel` above 100', function () { - const student = new Student(...this.properties) - student.skillLevel = 100 - student.study() + it("should cannot increase the student's `skillLevel` above 100", function () { + const student = new Student(...this.properties); + student.skillLevel = 100; + student.study(); - expect(student.skillLevel).to.equal(100) - }) + expect(student.skillLevel).to.equal(100); + }); - it('should be chainable (e.g. student.study().study().study())', function () { - const student = new Student(...this.properties) - student.study().study() + it("should be chainable (e.g. student.study().study().study())", function () { + const student = new Student(...this.properties); + student.study().study(); - expect(student.skillLevel).to.equal(this.properties[1] + 2) - }) - }) + expect(student.skillLevel).to.equal(this.properties[1] + 2); + }); + }); - describe('.doHomework()', function () { - it('accepts an object that includes a `skillLevel` key and marks it as complete (i.e. adds a key of `completed` with a value of `true` to the homework) if the student\'s skill level is above the inputted homework\'s `skillLevel`', function () { - const student = new Student(...this.properties) + describe(".doHomework()", function () { + it("accepts an object that includes a `skillLevel` key and marks it as complete (i.e. adds a key of `completed` with a value of `true` to the homework) if the student's skill level is above the inputted homework's `skillLevel`", function () { + const student = new Student(...this.properties); - const homework = { title: 'Crushing Candy Code', skillLevel: 38 } - student.doHomework(homework) + const homework = { title: "Crushing Candy Code", skillLevel: 38 }; + student.doHomework(homework); - expect(homework.completed).to.be.true - }) + expect(student.assignments[0].complete).to.be.true; + }); - it('marks homework as incomplete (i.e. `complete: false`) if the skillLevel is too high', function () { - const student = new Student(...this.properties) + it("marks homework as incomplete (i.e. `complete: false`) if the skillLevel is too high", function () { + const student = new Student(...this.properties); - const homework = { title: 'OOP Classroom', skillLevel: 47 } - student.doHomework(homework) + const homework = { title: "OOP Classroom", skillLevel: 47 }; + student.doHomework(homework); - expect(homework.completed).to.be.false - }) + expect(student.assignments[0].complete).to.be.false; + }); - it('adds the homework to the `assignments` array whether or not it is completed', function () { - const student = new Student(...this.properties) + it("adds the homework to the `assignments` array whether or not it is completed", function () { + const student = new Student(...this.properties); - const homework = { title: 'Crushing Candy Code', skillLevel: 38 } - student.doHomework(homework) + const homework = { title: "Crushing Candy Code", skillLevel: 38 }; + student.doHomework(homework); - expect(student.assignments).to.include(homework) - }) + expect(student.assignments).to.deep.include.members([ + { + title: "Crushing Candy Code", + skillLevel: 38, + complete: true, + }, + ]); + }); - it('does not add the homework to the `assignments` array if it does not have a `skillLevel`', function () { - const student = new Student(...this.properties) + it("does not add the homework to the `assignments` array if it does not have a `skillLevel`", function () { + const student = new Student(...this.properties); - const homework = { title: 'Crushing Candy Code' } - student.doHomework(homework) + const homework = { title: "Crushing Candy Code" }; + student.doHomework(homework); - expect(student.assignments).to.not.include(homework) - }) + expect(student.assignments).to.not.include(homework); + }); - it('does not add the homework to the `assignments` array if it\'s `skillLevel` is below 1', function () { - const student = new Student(...this.properties) + it("does not add the homework to the `assignments` array if it's `skillLevel` is below 1", function () { + const student = new Student(...this.properties); - const homework = { title: 'Crushing Candy Code', skillLevel: 0 } - student.doHomework(homework) + const homework = { title: "Crushing Candy Code", skillLevel: 0 }; + student.doHomework(homework); - expect(student.assignments).to.not.include(homework) - }) + expect(student.assignments).to.not.include(homework); + }); - it('does not add the homework to the `assignments` array if it\'s `skillLevel` is above 100', function () { - const student = new Student(...this.properties) + it("does not add the homework to the `assignments` array if it's `skillLevel` is above 100", function () { + const student = new Student(...this.properties); - const homework = { title: 'Get us to Pluto', skillLevel: 101 } - student.doHomework(homework) + const homework = { title: "Get us to Pluto", skillLevel: 101 }; + student.doHomework(homework); - expect(student.assignments).to.not.include(homework) - }) + expect(student.assignments).to.not.include(homework); + }); - it('if no argument is added, attempts to complete all incomplete homework and will complete it if the `skillLevel` is higher', function () { - const student = new Student(...this.properties) + it("if no argument is added, attempts to complete all incomplete homework and will complete it if the `skillLevel` is higher", function () { + const student = new Student(...this.properties); - const homework = { title: 'OOP Classroom', skillLevel: 47 } - student.doHomework(homework) + const homework = { title: "OOP Classroom", skillLevel: 47 }; + student.doHomework(homework); - expect(student.assignments).to.include(homework) + expect(student.assignments).to.deep.include.members([ + { + title: "OOP Classroom", + skillLevel: 47, + complete: false, + }, + ]); - student.study().study().study().study() - student.doHomework() + student.study().study().study().study(); + student.doHomework(); - expect(student.assignments[0].completed).to.be.true - }) + expect(student.assignments[0].complete).to.be.true; + }); - it('if no argument is added, attempts to complete all incomplete homework but it will stay incomplete if `skillLevel` is still not enough', function () { - const student = new Student(...this.properties) + it("if no argument is added, attempts to complete all incomplete homework but it will stay incomplete if `skillLevel` is still not enough", function () { + const student = new Student(...this.properties); - const homework = { title: 'Capstone Project', skillLevel: 90 } - student.doHomework(homework) + const homework = { title: "Capstone Project", skillLevel: 90 }; + student.doHomework(homework); - expect(student.assignments).to.include(homework) + expect(student.assignments).to.deep.include.members([ + { + title: "Capstone Project", + skillLevel: 90, + complete: false, + }, + ]); - student.study().study().study().study() - student.doHomework() - - expect(student.assignments[0].completed).to.be.false - }) - }) -}) + student.study().study().study().study(); + student.doHomework(); + expect(student.assignments[0].complete).to.be.false; + }); + }); +}); From 8d554d3fb48ff873c7b34e9c1b3431383ed333a4 Mon Sep 17 00:00:00 2001 From: Logan Thirion Date: Thu, 19 Nov 2020 09:26:22 -0600 Subject: [PATCH 2/2] fixed complete / completed discrepencies between test requirements and the expected prop --- test/student.test.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/student.test.js b/test/student.test.js index a32733c..8d70c0e 100644 --- a/test/student.test.js +++ b/test/student.test.js @@ -53,22 +53,22 @@ describe("Student", function () { }); describe(".doHomework()", function () { - it("accepts an object that includes a `skillLevel` key and marks it as complete (i.e. adds a key of `completed` with a value of `true` to the homework) if the student's skill level is above the inputted homework's `skillLevel`", function () { + it("accepts an object that includes a `skillLevel` key and marks it as completed (i.e. adds a key of `completed` with a value of `true` to the homework) if the student's skill level is above the inputted homework's `skillLevel`", function () { const student = new Student(...this.properties); const homework = { title: "Crushing Candy Code", skillLevel: 38 }; student.doHomework(homework); - expect(student.assignments[0].complete).to.be.true; + expect(student.assignments[0].completed).to.be.true; }); - it("marks homework as incomplete (i.e. `complete: false`) if the skillLevel is too high", function () { + it("marks homework as incomplete (i.e. `completed: false`) if the skillLevel is too high", function () { const student = new Student(...this.properties); const homework = { title: "OOP Classroom", skillLevel: 47 }; student.doHomework(homework); - expect(student.assignments[0].complete).to.be.false; + expect(student.assignments[0].completed).to.be.false; }); it("adds the homework to the `assignments` array whether or not it is completed", function () { @@ -81,7 +81,7 @@ describe("Student", function () { { title: "Crushing Candy Code", skillLevel: 38, - complete: true, + completed: true, }, ]); }); @@ -123,14 +123,14 @@ describe("Student", function () { { title: "OOP Classroom", skillLevel: 47, - complete: false, + completed: false, }, ]); student.study().study().study().study(); student.doHomework(); - expect(student.assignments[0].complete).to.be.true; + expect(student.assignments[0].completed).to.be.true; }); it("if no argument is added, attempts to complete all incomplete homework but it will stay incomplete if `skillLevel` is still not enough", function () { @@ -143,13 +143,13 @@ describe("Student", function () { { title: "Capstone Project", skillLevel: 90, - complete: false, + completed: false, }, ]); student.study().study().study().study(); student.doHomework(); - expect(student.assignments[0].complete).to.be.false; + expect(student.assignments[0].completed).to.be.false; }); }); });