From 1b1c1fd496fba6325964411d9036fb9dc8f0266a Mon Sep 17 00:00:00 2001 From: bs98 Date: Wed, 16 Oct 2019 03:28:00 -0400 Subject: [PATCH 1/7] Task Compliance for Javascript Prototypes --- instanceArray.js | 22 +++++++++++++++++- quizApp.js | 60 ++++++++++++++++++++++++++++++++++++++++++++++-- sayName.js | 13 +++++++++-- user.json | 4 ++-- 4 files changed, 92 insertions(+), 7 deletions(-) diff --git a/instanceArray.js b/instanceArray.js index ab752ac..622e306 100644 --- a/instanceArray.js +++ b/instanceArray.js @@ -14,28 +14,48 @@ var User = function(name, email, pw){ //Create an Array called 'users' that will store all our instances of User. //code here + let users = []; //Now create and push into your users array 3 separate instances of User using the data from above in that exact order //code here + users.push(new User('Aodhan', 'aodhan@boom.camp', 'iLoveJS')); + users.push(new User('Greg', 'greg@boom.camp', 'iLovePython')); + users.push(new User('Oscar', 'oscar@boom.camp', 'iLoveSoccer')); + console.log('Aodhan\'s information is '); //Console.log all of Aodhan information //code here + users.map(user=>{ + if(user.name === "Aodhan"){ + console.log(" Registered Email: " + user.email + " and Registered Password:" + user.pw); + } + }); console.log('Oscar\'s information is '); //Now console.log all of Oscars information //code here + users.map(user=>{ + if(user.name === "Oscar"){ + console.log(" Registered Email: " + user.email + " and Registered Password:" + user.pw); + } + }); //Now create another instance of User using your own information and then add that to your users array. //code here - + users.push(new User('Yow','jeffrey.molleno@boom.camp','thirdwheelingmajor')); console.log('All my users names are '); //Now loop through your users Array and console.log every users name. //code here + users.map(user=>{ + if(user.name === "Yow"){ + console.log(" Registered Email: " + user.email + " and Registered Password:" + user.pw); + } + }); diff --git a/quizApp.js b/quizApp.js index 083bd6c..74d18f8 100644 --- a/quizApp.js +++ b/quizApp.js @@ -7,26 +7,61 @@ //code here + function QuizUser(name, email, password, totalScore){ + this.name = name; + this.email= email; + this.password = password; + this.totalScore = totalScore; + } + //Create a Question constructor that accepts title, answersArray, rightAnswer, and difficulty parameters //code here + function Question(title, answersArray, rightAnswer, difficulty){ + this.title = title; + this.answersArray = answersArray; + this.rightAnswer = rightAnswer; + this.difficulty = difficulty; + } + //Create a quizUsers Array which is going to hold all of our users. //code here +var quizUsers = []; //Let's say three people signed up for our service, create 3 instances of User and add each to the users Array //code here +quizUsers = [ + { + name: "Yow", + email: "jeffrey.molleno@boom.camp", + password: "sadlyf", + totalScore: "" + }, + { + name: "Loki", + email: "loki@boom.camp", + password: "qiqil", + totalScore: "" + }, + { + name: "Aquila", + email: "aquila@boom", + password: "sanaall", + totalScore: "" + } + ]; //Create a questions Array which is going to hold all of our questions //code here - +var questions = []; //Now, let's say we wanted to create a quiz about JavaScript. Create three instances of Question which contain the following data //title: 'T/F: Inheritance is achieved in JavaScript through Prototypes?' @@ -35,14 +70,35 @@ //Fill in the rest of the required data as you see appropriate. //code here - +questions = [{ + title: 'T/F: Inheritance is achieved in JavaScript through Prototypes?', + answersArray : 'True or False', + rightAnswer : 'True', + difficulty: 'Advance' +}, +{ + title: 'T/F: JavaScript is just a scripting version of Java', + answersArray : 'True or False', + rightAnswer : 'False', + difficulty: 'Basic' +}, +{ + title: "T/F: In Javascript, == doesn't check 'type' but just the value - where === checks type and value", + answersArray : 'True or False', + rightAnswer : 'True' , + difficulty: 'Intermediate' +}] //Now push all of your instances of Question into the questions Array //code here + // Question.map(ask=>questions.push(ask)); console.log('My users Array and my questions arrray are ...'); //Now loop console.log your users array and your questions array and verify that they're both holding the right data. //code here + quizUsers.map(user=>console.log(user)); + + questions.map(ask=>console.log(ask)); diff --git a/sayName.js b/sayName.js index 6e28b51..de63580 100644 --- a/sayName.js +++ b/sayName.js @@ -1,13 +1,22 @@ //Create a Person constructor that accepts name and age as parameters and sets those properties accordingly in the Constructor. //code here - + function Person(name, age){ + this.name = name; + this.age = age; + } //Now create three instances of Person with data you make up //code here - + let beb = new Person("P****","23"); + let friend = new Person("Zel","21"); + let must_protect = new Person("Jai","3"); //Now add a sayName method on your Person class that will alert the name of whatever Person instance called it. //code here + Person.prototype.sayName = function(){ + alert(this.name); + }; + diff --git a/user.json b/user.json index 4ac80a0..47f4ea9 100644 --- a/user.json +++ b/user.json @@ -1,4 +1,4 @@ { - "name": "", - "email": "" + "name": "Jeffrey Molleno", + "email": "jeffrey.molleno@boom.camp" } From c05a354514313757b21194bd3ee823a320715ad1 Mon Sep 17 00:00:00 2001 From: bs98 Date: Wed, 16 Oct 2019 03:40:15 -0400 Subject: [PATCH 2/7] Final Commit with the addition of Extending String Class --- arrayProperty.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arrayProperty.js b/arrayProperty.js index 2287a36..66ad444 100644 --- a/arrayProperty.js +++ b/arrayProperty.js @@ -2,4 +2,12 @@ //Add a reverse method to the String 'class' so that every instance of String can call reverse and reverse itself. - //code here \ No newline at end of file + //code here + + // class String extends String{ + + // } + String.prototype.reverses = function(){ + return this.split("").reverse + ().join(""); + } \ No newline at end of file From b222c1b9dbf19f7a108a0a3ed17afebf362c0ccc Mon Sep 17 00:00:00 2001 From: JeffreyMolleno <55709839+JeffreyMolleno@users.noreply.github.com> Date: Wed, 16 Oct 2019 03:42:25 -0400 Subject: [PATCH 3/7] Update arrayProperty.js --- arrayProperty.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/arrayProperty.js b/arrayProperty.js index 66ad444..ceb3953 100644 --- a/arrayProperty.js +++ b/arrayProperty.js @@ -7,7 +7,6 @@ // class String extends String{ // } - String.prototype.reverses = function(){ - return this.split("").reverse - ().join(""); - } \ No newline at end of file + String.prototype.reverse = function(){ + return this.split("").reverse().join(""); + } From 1c246c44f7ca6f99119c89b1988c4d0f10c379de Mon Sep 17 00:00:00 2001 From: bs98 Date: Wed, 16 Oct 2019 04:08:21 -0400 Subject: [PATCH 4/7] Compliance V2 --- arrayProperty.js | 5 ++- quizApp.js | 86 ++++++++++++++++++++++++++---------------------- 2 files changed, 49 insertions(+), 42 deletions(-) diff --git a/arrayProperty.js b/arrayProperty.js index 66ad444..a58fafb 100644 --- a/arrayProperty.js +++ b/arrayProperty.js @@ -7,7 +7,6 @@ // class String extends String{ // } - String.prototype.reverses = function(){ - return this.split("").reverse - ().join(""); + String.prototype.reverse = function(){ + return this.split("").reverse().join(""); } \ No newline at end of file diff --git a/quizApp.js b/quizApp.js index 74d18f8..1257bd3 100644 --- a/quizApp.js +++ b/quizApp.js @@ -36,26 +36,10 @@ var quizUsers = []; //Let's say three people signed up for our service, create 3 instances of User and add each to the users Array //code here -quizUsers = [ - { - name: "Yow", - email: "jeffrey.molleno@boom.camp", - password: "sadlyf", - totalScore: "" - }, - { - name: "Loki", - email: "loki@boom.camp", - password: "qiqil", - totalScore: "" - }, - { - name: "Aquila", - email: "aquila@boom", - password: "sanaall", - totalScore: "" - } - ]; + + quizUsers.push(new QuizUser("Yow", "jeffrey.molleno@boom.camp", "sadlyf", 0 )); + quizUsers.push(new QuizUser("Loki", "loki@boom.camp", "qiqil", 0 )); + quizUsers.push(new QuizUser("Aquila", "Aquila@boom.camp", "sanaall", 0 )); //Create a questions Array which is going to hold all of our questions @@ -70,29 +54,53 @@ var questions = []; //Fill in the rest of the required data as you see appropriate. //code here -questions = [{ - title: 'T/F: Inheritance is achieved in JavaScript through Prototypes?', - answersArray : 'True or False', - rightAnswer : 'True', - difficulty: 'Advance' -}, -{ - title: 'T/F: JavaScript is just a scripting version of Java', - answersArray : 'True or False', - rightAnswer : 'False', - difficulty: 'Basic' -}, -{ - title: "T/F: In Javascript, == doesn't check 'type' but just the value - where === checks type and value", - answersArray : 'True or False', - rightAnswer : 'True' , - difficulty: 'Intermediate' -}] + + let question1 = { + title: 'T/F: Inheritance is achieved in JavaScript through Prototypes?', + answersArray : 'True or False', + rightAnswer : 'True', + difficulty: 'Advance' + }; + + let question2 = { + title: 'T/F: JavaScript is just a scripting version of Java', + answersArray : 'True or False', + rightAnswer : 'False', + difficulty: 'Basic' + }; + + let question3 = { + title: "T/F: In Javascript, == doesn't check 'type' but just the value - where === checks type and value", + answersArray : 'True or False', + rightAnswer : 'True' , + difficulty: 'Intermediate' + }; + +// questions = [{ +// title: 'T/F: Inheritance is achieved in JavaScript through Prototypes?', +// answersArray : 'True or False', +// rightAnswer : 'True', +// difficulty: 'Advance' +// }, +// { +// title: 'T/F: JavaScript is just a scripting version of Java', +// answersArray : 'True or False', +// rightAnswer : 'False', +// difficulty: 'Basic' +// }, +// { +// title: "T/F: In Javascript, == doesn't check 'type' but just the value - where === checks type and value", +// answersArray : 'True or False', +// rightAnswer : 'True' , +// difficulty: 'Intermediate' +// }] //Now push all of your instances of Question into the questions Array //code here - // Question.map(ask=>questions.push(ask)); + questions.push(question1); + questions.push(question2); + questions.push(question3); console.log('My users Array and my questions arrray are ...'); //Now loop console.log your users array and your questions array and verify that they're both holding the right data. From 152124aa29b799e1d165db29f0ec3af723ade1f6 Mon Sep 17 00:00:00 2001 From: bs98 Date: Wed, 16 Oct 2019 05:07:06 -0400 Subject: [PATCH 5/7] Remove anomaly on String reverse solution --- arrayProperty.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/arrayProperty.js b/arrayProperty.js index 119b478..a58fafb 100644 --- a/arrayProperty.js +++ b/arrayProperty.js @@ -9,8 +9,4 @@ // } String.prototype.reverse = function(){ return this.split("").reverse().join(""); -<<<<<<< HEAD - } -======= - } ->>>>>>> b222c1b9dbf19f7a108a0a3ed17afebf362c0ccc + } \ No newline at end of file From a9fcd0e617ce462ffee4d26c21d7e246af7f1de4 Mon Sep 17 00:00:00 2001 From: bs98 Date: Thu, 17 Oct 2019 02:57:19 -0400 Subject: [PATCH 6/7] Changes to spec --- arrayProperty.js | 6 +- test/spec.zip | Bin 0 -> 3571 bytes test/spec/arrayPropertySpec.js | 7 -- test/spec/quizAppSpec.js | 7 -- test/spec/sayNameSpec.js | 7 -- test/spec_2/arrayPropertySpec.js | 43 ++++++++++++ test/spec_2/instanceArraySpec.js | 49 ++++++++++++++ test/spec_2/quizAppSpec.js | 113 +++++++++++++++++++++++++++++++ test/spec_2/sayNameSpec.js | 65 ++++++++++++++++++ 9 files changed, 271 insertions(+), 26 deletions(-) create mode 100644 test/spec.zip create mode 100644 test/spec_2/arrayPropertySpec.js create mode 100644 test/spec_2/instanceArraySpec.js create mode 100644 test/spec_2/quizAppSpec.js create mode 100644 test/spec_2/sayNameSpec.js diff --git a/arrayProperty.js b/arrayProperty.js index a58fafb..91a8365 100644 --- a/arrayProperty.js +++ b/arrayProperty.js @@ -3,10 +3,6 @@ //Add a reverse method to the String 'class' so that every instance of String can call reverse and reverse itself. //code here - - // class String extends String{ - - // } String.prototype.reverse = function(){ return this.split("").reverse().join(""); - } \ No newline at end of file + } diff --git a/test/spec.zip b/test/spec.zip new file mode 100644 index 0000000000000000000000000000000000000000..8a895d9166d99206d79136c802f5ed68113d9aef GIT binary patch literal 3571 zcmbVP2{e>lADFJD1@=o zSh6SKZHO%MnZDP_+d1Dk-}~O@Jonz`Jm>uW_n!Ov{qOIO)T5$i15g^fnW4eY$zL4} z;3UAu)6rhS#25;ovm7b0K6w2CApjut0u=!8vqS!b00Y2)>xUpd?*Bf10Ac6tZ5M>} z_V9G{_6@qc4=V2J^AmP^AC_sf#F{ex2AgpClE-}n^UH4{bIk9~Cv+Z(8PyojR4_>) z*kfBD8moiX)2i)iVmDW~;KM}W6T+Z)We=zE5V>0}YT2uO@`4?#HV|}KWXvg$wuL>* zMF8x+^jG?LDrjPLPuden>f1x(lJ(G4cJKo_4M8oqW{_X}`dR<^UKxY6%Tjgt95tb0 za8w=7dkp4na-U)Yb%AlKe2HT?R~kd^i5pb#86i;6iHIpH9MnopUJ0*KZ&5kWaraKq zv-}F0i8-8GJ8`Rm%zG<$qNWA96{Z>)_7yE*c7z2lg}&yinOalqF;eBr2jBkaU=8Hp zr1M7ZnvQuIK63aRkGD8^G#|PtS2WNNNIp=ezk0FWwAP1;$(}u<0mg+hK>1SX`(Pj*(|6>IzIuU_@}awQj8vo?uzzw?tQ;J z^!JqES9M^2{tMMNOiHvJ0_e4Q2VcG!-kN*Ki8e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215d 100644 --- a/test/spec/arrayPropertySpec.js +++ b/test/spec/arrayPropertySpec.js @@ -1,10 +1,3 @@ -const isNode = new Function(` - try { - return this === global; - } catch (e) { - return false; - } -`); if (isNode()) { // test if file is running in a node process diff --git a/test/spec/quizAppSpec.js b/test/spec/quizAppSpec.js index 8e0c63c..ecb9af5 100644 --- a/test/spec/quizAppSpec.js +++ b/test/spec/quizAppSpec.js @@ -1,10 +1,3 @@ -const isNode = new Function(` - try { - return this === global; - } catch (e) { - return false; - } -`); if (isNode()) { // test if file is running in a node process diff --git a/test/spec/sayNameSpec.js b/test/spec/sayNameSpec.js index 7fbb7bb..8b76117 100644 --- a/test/spec/sayNameSpec.js +++ b/test/spec/sayNameSpec.js @@ -1,10 +1,3 @@ -const isNode = new Function(` - try { - return this === global; - } catch (e) { - return false; - } -`); if (isNode()) { // test if file is running in a node process diff --git a/test/spec_2/arrayPropertySpec.js b/test/spec_2/arrayPropertySpec.js new file mode 100644 index 0000000..6907a75 --- /dev/null +++ b/test/spec_2/arrayPropertySpec.js @@ -0,0 +1,43 @@ +const isNode = new Function(` + try { + return this === global; + } catch (e) { + return false; + } +`); + +if (isNode()) { + // test if file is running in a node process + const fs = require('fs'); + const path = require('path'); + + const filePath = path.resolve(__dirname, '../../'); // this should be the root dir + fs.readdirSync(filePath) // eval all of the js files faking how a browser would execute + .filter(path => { + if (path) { + return /\.js$/.test(path); + } else { + return false; + } + }) + .forEach(file => { + global.eval(fs.readFileSync(`${filePath}/${file}`) + ''); + }); +} + +// Test +describe('arrayProperty', function() { + describe('String', function() { + it('should have a reverse method', function() { + var str = 'Hello'; + expect(str.reverse).toBeDefined(); + expect(str.reverse).toEqual(jasmine.any(Function)); + }); + describe('reverse method', function() { + it('should reverse the string', function() { + var str = 'Hello'; + expect(str.reverse()).toEqual('olleH'); + }); + }); + }); +}); diff --git a/test/spec_2/instanceArraySpec.js b/test/spec_2/instanceArraySpec.js new file mode 100644 index 0000000..91e6170 --- /dev/null +++ b/test/spec_2/instanceArraySpec.js @@ -0,0 +1,49 @@ +const isNode = new Function(` + try { + return this === global; + } catch (e) { + return false; + } +`); + +if (isNode()) { + // test if file is running in a node process + const fs = require('fs'); + const path = require('path'); + + const filePath = path.resolve(__dirname, '../../'); // this should be the root dir + fs.readdirSync(filePath) // eval all of the js files faking how a browser would execute + .filter(path => { + if (path) { + return /\.js$/.test(path); + } else { + return false; + } + }) + .forEach(file => { + global.eval(fs.readFileSync(`${filePath}/${file}`) + ''); + }); +} + +describe('instanceArray', function() { + describe('users', function() { + it('should exist', function() { + expect(users).toBeDefined(); + }); + it('should be an array', function() { + expect(users).toEqual(jasmine.any(Array)); + }); + it('should have 4 items', function() { + expect(users.length).toBe(4); + }); + it('should contain all instances of User', function() { + var areAllUsers = true; + for (var i = 0; i < users.length; i++) { + if (!users[i] instanceof User) { + areAllUsers = false; + } + } + expect(areAllUsers).toBe(true); + }); + }); +}); diff --git a/test/spec_2/quizAppSpec.js b/test/spec_2/quizAppSpec.js new file mode 100644 index 0000000..8e0c63c --- /dev/null +++ b/test/spec_2/quizAppSpec.js @@ -0,0 +1,113 @@ +const isNode = new Function(` + try { + return this === global; + } catch (e) { + return false; + } +`); + +if (isNode()) { + // test if file is running in a node process + const fs = require('fs'); + const path = require('path'); + + const filePath = path.resolve(__dirname, '../../'); // this should be the root dir + fs.readdirSync(filePath) // eval all of the js files faking how a browser would execute + .filter(path => { + if (path) { + return /\.js$/.test(path); + } else { + return false; + } + }) + .forEach(file => { + global.eval(fs.readFileSync(`${filePath}/${file}`) + ''); + }); +} + +describe('quizApp', function() { + describe('QuizUser', function() { + it('should exist', function() { + expect(QuizUser).toBeDefined(); + }); + it('should be a function', function() { + expect(QuizUser).toEqual(jasmine.any(Function)); + }); + it('should return an object when called with new', function() { + var quizUser = new QuizUser('Tester', 'test', 'test', 0); + expect(quizUser).toEqual(jasmine.any(Object)); + }); + describe('return object', function() { + it('should have name, email, password, and totalScore properties', function() { + var quizUser = new QuizUser('Tester', 'test', 'test', 0); + expect(quizUser.hasOwnProperty('name')).toBe(true); + expect(quizUser.hasOwnProperty('email')).toBe(true); + expect(quizUser.hasOwnProperty('password')).toBe(true); + expect(quizUser.hasOwnProperty('totalScore')).toBe(true); + }); + }); + }); + describe('Question', function() { + it('should exist', function() { + expect(Question).toBeDefined(); + }); + it('should be a function', function() { + expect(Question).toEqual(jasmine.any(Function)); + }); + it('should return an object when called with new', function() { + var question = new Question('Tester', 'test', 'test', 0); + expect(question).toEqual(jasmine.any(Object)); + }); + describe('return object', function() { + it('should have title, answersArray, rightAnswer, and difficulty properties', function() { + var question = new Question('Tester', 'test', 'test', 0); + expect(question.hasOwnProperty('title')).toBe(true); + expect(question.hasOwnProperty('answersArray')).toBe(true); + expect(question.hasOwnProperty('rightAnswer')).toBe(true); + expect(question.hasOwnProperty('difficulty')).toBe(true); + }); + }); + }); + describe('quizUsers', function() { + it('should exist', function() { + expect(quizUsers).toBeDefined(); + }); + it('should be an array', function() { + expect(quizUsers).toEqual(jasmine.any(Array)); + }); + it('should have three items', function() { + expect(quizUsers.length).toBe(3); + }); + it('(when complete) should only contain instances of QuizUser', function() { + var areAllUsers = true; + var quizUsers = quizUsers || []; + for (var i = 0; i < quizUsers.length; i++) { + if (!users[i] instanceof QuizUser) { + areAllUsers = false; + } + } + expect(areAllUsers).toBe(true); + }); + }); + describe('questions', function() { + it('should exist', function() { + expect(questions).toBeDefined(); + }); + it('should be an array', function() { + expect(questions).toEqual(jasmine.any(Array)); + }); + it('should have three items', function() { + expect(questions.length).toBe(3); + }); + it('(when complete) should only contain instances of Question', function() { + var areAllQuestions = true; + var questions = questions || []; + for (var i = 0; i < questions.length; i++) { + if (!questions[i] instanceof Question) { + areAllQuestions = false; + } + } + expect(areAllQuestions).toBe(true); + }); + }); +}); diff --git a/test/spec_2/sayNameSpec.js b/test/spec_2/sayNameSpec.js new file mode 100644 index 0000000..7fbb7bb --- /dev/null +++ b/test/spec_2/sayNameSpec.js @@ -0,0 +1,65 @@ +const isNode = new Function(` + try { + return this === global; + } catch (e) { + return false; + } +`); + +if (isNode()) { + // test if file is running in a node process + const fs = require('fs'); + const path = require('path'); + + const filePath = path.resolve(__dirname, '../../'); // this should be the root dir + fs.readdirSync(filePath) // eval all of the js files faking how a browser would execute + .filter(path => { + if (path) { + return /\.js$/.test(path); + } else { + return false; + } + }) + .forEach(file => { + global.eval(fs.readFileSync(`${filePath}/${file}`) + ''); + }); +} + +describe('sayName', function() { + describe('Person', function() { + it('should exist', function() { + expect(Person).toBeDefined(); + }); + it('should be a function', function() { + expect(Person).toEqual(jasmine.any(Function)); + }); + it('should return an object with name and age properties when invoked with new (e.g. var person = new Person(...))', function() { + var person = new Person('Tester', 25); + expect(person.hasOwnProperty('name')).toBe(true); + expect(person.hasOwnProperty('age')).toBe(true); + }); + describe('return object', function() { + it('should be an instance of Person', function() { + var person = new Person('Tester', 25); + var isPerson = person instanceof Person; + expect(isPerson).toBe(true); + }); + it('should have access to a sayName method', function() { + var person = new Person('Tester', 25); + expect(person.sayName).toBeDefined(); + expect(person.sayName).toEqual(jasmine.any(Function)); + }); + describe('sayName', function() { + it('should alert the name of the person on which sayName is invoked', function() { + var tester = new Person('Tester', 25); + var someoneElse = new Person('Simone Elsa', 22); + var alert = spyOn(window, 'alert'); + tester.sayName(); + expect(alert).toHaveBeenCalledWith('Tester'); + someoneElse.sayName(); + expect(alert).toHaveBeenCalledWith('Simone Elsa'); + }); + }); + }); + }); +}); From 3afae9b2deea34eda19e8ba2a7dc4604777e1e0d Mon Sep 17 00:00:00 2001 From: bs98 Date: Thu, 17 Oct 2019 03:37:10 -0400 Subject: [PATCH 7/7] Changes to Spec --- test/spec.zip | Bin 3571 -> 0 bytes test/spec/arrayPropertySpec.js | 7 ++ test/spec/quizAppSpec.js | 7 ++ test/spec/sayNameSpec.js | 7 ++ test/spec_2/arrayPropertySpec.js | 43 ------------ test/spec_2/instanceArraySpec.js | 49 -------------- test/spec_2/quizAppSpec.js | 113 ------------------------------- test/spec_2/sayNameSpec.js | 65 ------------------ 8 files changed, 21 insertions(+), 270 deletions(-) delete mode 100644 test/spec.zip delete mode 100644 test/spec_2/arrayPropertySpec.js delete mode 100644 test/spec_2/instanceArraySpec.js delete mode 100644 test/spec_2/quizAppSpec.js delete mode 100644 test/spec_2/sayNameSpec.js diff --git a/test/spec.zip b/test/spec.zip deleted file mode 100644 index 8a895d9166d99206d79136c802f5ed68113d9aef..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3571 zcmbVP2{e>lADFJD1@=o zSh6SKZHO%MnZDP_+d1Dk-}~O@Jonz`Jm>uW_n!Ov{qOIO)T5$i15g^fnW4eY$zL4} z;3UAu)6rhS#25;ovm7b0K6w2CApjut0u=!8vqS!b00Y2)>xUpd?*Bf10Ac6tZ5M>} z_V9G{_6@qc4=V2J^AmP^AC_sf#F{ex2AgpClE-}n^UH4{bIk9~Cv+Z(8PyojR4_>) z*kfBD8moiX)2i)iVmDW~;KM}W6T+Z)We=zE5V>0}YT2uO@`4?#HV|}KWXvg$wuL>* zMF8x+^jG?LDrjPLPuden>f1x(lJ(G4cJKo_4M8oqW{_X}`dR<^UKxY6%Tjgt95tb0 za8w=7dkp4na-U)Yb%AlKe2HT?R~kd^i5pb#86i;6iHIpH9MnopUJ0*KZ&5kWaraKq zv-}F0i8-8GJ8`Rm%zG<$qNWA96{Z>)_7yE*c7z2lg}&yinOalqF;eBr2jBkaU=8Hp zr1M7ZnvQuIK63aRkGD8^G#|PtS2WNNNIp=ezk0FWwAP1;$(}u<0mg+hK>1SX`(Pj*(|6>IzIuU_@}awQj8vo?uzzw?tQ;J z^!JqES9M^2{tMMNOiHvJ0_e4Q2VcG!-kN*Ki8eeMtrL2>Ma*KU)s^lQ$xQp5WNp8Y z329=D?%7*Ao{sK_p>8Tg+<;vh3QJTQ7wzhhmLLQYHdI2pjVo7u8(w3cg$nL!$A749ndq*`2 zaSjt^XSl@r;Qfs-e*1(OLomMFzT&A0?9j1W>9M>A;u_?R1HRE8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%x6vY6G_p|y?w#2k{1xmZxt$L2uZgR`>KRcXJ=w*FR4@#yUHSzKHBfbWr)p&LZjON)gNV7M2$mdz`{aA;^#x0k3NDAml1D zqotO6d@!+U$kx(=F2tYjxk0Ak3RykV?cq&{PPNI9V@^3sHqm%8JV>yUNnZRzctvAl z)EW6P*s*z7El`f^7k-s;(yz zmw53kuj2riv|@dZx1*X^tOXr;+MY$sol4D)Va-GYl&Rh;UOfxU)Nd}VR+YwlB!45p&f{DiXK#gD77 zKtbJGRtV8lUkpEN9Oh!_|Q3B6%g;R zoW*OB_A?phzRoNdB7=nh9Hc#RoUddGIJ066>k|ok^X+{cY~Hrt^}|x8bI-<Vd)Py zUtHAm;;W~YwKY;g(TLSAX~9I$5<47bMb9F$ODd3rx#3c0(bKG!S2M+=hCQLzZ5eCp z;7sY&q8$WMee~tKGw@nw*VERaoY{h(p_}EO=3b@OAV=@&NuH|i!HL8ty@s>Kv%yH-~`e6uVz1g`=BHo(^4ZVjD1|8 zX#?f%9pU=^{!ve}(9)%#jLQ*M`x(+(-~pvyYq(ot`O!}GMK+wss7MjS((+4(isW0a zixtzDG-cn?vhNwoU9EhpqVqdfT+^;=Ze@+1F$*n;vSY4lgR}3gM6|)QXTDxdctd=! zMcSpIC?z@;!vAjn(xd1BsRsnHQT=c4e^3kTs!?V>|6e8WU&w=6;IQeV)B*<$7ol+g z`EM$NgOyXlP#omptNia_eE0YIbLIcWPaY0K@dby|48<25G+YD?&0k^unM*hvfRe2a jpU&R{^z5J4&wc!}+=bMmp{1;nX8)N60sucCl&}8)nVA7* diff --git a/test/spec/arrayPropertySpec.js b/test/spec/arrayPropertySpec.js index b68215d..6907a75 100644 --- a/test/spec/arrayPropertySpec.js +++ b/test/spec/arrayPropertySpec.js @@ -1,3 +1,10 @@ +const isNode = new Function(` + try { + return this === global; + } catch (e) { + return false; + } +`); if (isNode()) { // test if file is running in a node process diff --git a/test/spec/quizAppSpec.js b/test/spec/quizAppSpec.js index ecb9af5..8e0c63c 100644 --- a/test/spec/quizAppSpec.js +++ b/test/spec/quizAppSpec.js @@ -1,3 +1,10 @@ +const isNode = new Function(` + try { + return this === global; + } catch (e) { + return false; + } +`); if (isNode()) { // test if file is running in a node process diff --git a/test/spec/sayNameSpec.js b/test/spec/sayNameSpec.js index 8b76117..7fbb7bb 100644 --- a/test/spec/sayNameSpec.js +++ b/test/spec/sayNameSpec.js @@ -1,3 +1,10 @@ +const isNode = new Function(` + try { + return this === global; + } catch (e) { + return false; + } +`); if (isNode()) { // test if file is running in a node process diff --git a/test/spec_2/arrayPropertySpec.js b/test/spec_2/arrayPropertySpec.js deleted file mode 100644 index 6907a75..0000000 --- a/test/spec_2/arrayPropertySpec.js +++ /dev/null @@ -1,43 +0,0 @@ -const isNode = new Function(` - try { - return this === global; - } catch (e) { - return false; - } -`); - -if (isNode()) { - // test if file is running in a node process - const fs = require('fs'); - const path = require('path'); - - const filePath = path.resolve(__dirname, '../../'); // this should be the root dir - fs.readdirSync(filePath) // eval all of the js files faking how a browser would execute - .filter(path => { - if (path) { - return /\.js$/.test(path); - } else { - return false; - } - }) - .forEach(file => { - global.eval(fs.readFileSync(`${filePath}/${file}`) + ''); - }); -} - -// Test -describe('arrayProperty', function() { - describe('String', function() { - it('should have a reverse method', function() { - var str = 'Hello'; - expect(str.reverse).toBeDefined(); - expect(str.reverse).toEqual(jasmine.any(Function)); - }); - describe('reverse method', function() { - it('should reverse the string', function() { - var str = 'Hello'; - expect(str.reverse()).toEqual('olleH'); - }); - }); - }); -}); diff --git a/test/spec_2/instanceArraySpec.js b/test/spec_2/instanceArraySpec.js deleted file mode 100644 index 91e6170..0000000 --- a/test/spec_2/instanceArraySpec.js +++ /dev/null @@ -1,49 +0,0 @@ -const isNode = new Function(` - try { - return this === global; - } catch (e) { - return false; - } -`); - -if (isNode()) { - // test if file is running in a node process - const fs = require('fs'); - const path = require('path'); - - const filePath = path.resolve(__dirname, '../../'); // this should be the root dir - fs.readdirSync(filePath) // eval all of the js files faking how a browser would execute - .filter(path => { - if (path) { - return /\.js$/.test(path); - } else { - return false; - } - }) - .forEach(file => { - global.eval(fs.readFileSync(`${filePath}/${file}`) + ''); - }); -} - -describe('instanceArray', function() { - describe('users', function() { - it('should exist', function() { - expect(users).toBeDefined(); - }); - it('should be an array', function() { - expect(users).toEqual(jasmine.any(Array)); - }); - it('should have 4 items', function() { - expect(users.length).toBe(4); - }); - it('should contain all instances of User', function() { - var areAllUsers = true; - for (var i = 0; i < users.length; i++) { - if (!users[i] instanceof User) { - areAllUsers = false; - } - } - expect(areAllUsers).toBe(true); - }); - }); -}); diff --git a/test/spec_2/quizAppSpec.js b/test/spec_2/quizAppSpec.js deleted file mode 100644 index 8e0c63c..0000000 --- a/test/spec_2/quizAppSpec.js +++ /dev/null @@ -1,113 +0,0 @@ -const isNode = new Function(` - try { - return this === global; - } catch (e) { - return false; - } -`); - -if (isNode()) { - // test if file is running in a node process - const fs = require('fs'); - const path = require('path'); - - const filePath = path.resolve(__dirname, '../../'); // this should be the root dir - fs.readdirSync(filePath) // eval all of the js files faking how a browser would execute - .filter(path => { - if (path) { - return /\.js$/.test(path); - } else { - return false; - } - }) - .forEach(file => { - global.eval(fs.readFileSync(`${filePath}/${file}`) + ''); - }); -} - -describe('quizApp', function() { - describe('QuizUser', function() { - it('should exist', function() { - expect(QuizUser).toBeDefined(); - }); - it('should be a function', function() { - expect(QuizUser).toEqual(jasmine.any(Function)); - }); - it('should return an object when called with new', function() { - var quizUser = new QuizUser('Tester', 'test', 'test', 0); - expect(quizUser).toEqual(jasmine.any(Object)); - }); - describe('return object', function() { - it('should have name, email, password, and totalScore properties', function() { - var quizUser = new QuizUser('Tester', 'test', 'test', 0); - expect(quizUser.hasOwnProperty('name')).toBe(true); - expect(quizUser.hasOwnProperty('email')).toBe(true); - expect(quizUser.hasOwnProperty('password')).toBe(true); - expect(quizUser.hasOwnProperty('totalScore')).toBe(true); - }); - }); - }); - describe('Question', function() { - it('should exist', function() { - expect(Question).toBeDefined(); - }); - it('should be a function', function() { - expect(Question).toEqual(jasmine.any(Function)); - }); - it('should return an object when called with new', function() { - var question = new Question('Tester', 'test', 'test', 0); - expect(question).toEqual(jasmine.any(Object)); - }); - describe('return object', function() { - it('should have title, answersArray, rightAnswer, and difficulty properties', function() { - var question = new Question('Tester', 'test', 'test', 0); - expect(question.hasOwnProperty('title')).toBe(true); - expect(question.hasOwnProperty('answersArray')).toBe(true); - expect(question.hasOwnProperty('rightAnswer')).toBe(true); - expect(question.hasOwnProperty('difficulty')).toBe(true); - }); - }); - }); - describe('quizUsers', function() { - it('should exist', function() { - expect(quizUsers).toBeDefined(); - }); - it('should be an array', function() { - expect(quizUsers).toEqual(jasmine.any(Array)); - }); - it('should have three items', function() { - expect(quizUsers.length).toBe(3); - }); - it('(when complete) should only contain instances of QuizUser', function() { - var areAllUsers = true; - var quizUsers = quizUsers || []; - for (var i = 0; i < quizUsers.length; i++) { - if (!users[i] instanceof QuizUser) { - areAllUsers = false; - } - } - expect(areAllUsers).toBe(true); - }); - }); - describe('questions', function() { - it('should exist', function() { - expect(questions).toBeDefined(); - }); - it('should be an array', function() { - expect(questions).toEqual(jasmine.any(Array)); - }); - it('should have three items', function() { - expect(questions.length).toBe(3); - }); - it('(when complete) should only contain instances of Question', function() { - var areAllQuestions = true; - var questions = questions || []; - for (var i = 0; i < questions.length; i++) { - if (!questions[i] instanceof Question) { - areAllQuestions = false; - } - } - expect(areAllQuestions).toBe(true); - }); - }); -}); diff --git a/test/spec_2/sayNameSpec.js b/test/spec_2/sayNameSpec.js deleted file mode 100644 index 7fbb7bb..0000000 --- a/test/spec_2/sayNameSpec.js +++ /dev/null @@ -1,65 +0,0 @@ -const isNode = new Function(` - try { - return this === global; - } catch (e) { - return false; - } -`); - -if (isNode()) { - // test if file is running in a node process - const fs = require('fs'); - const path = require('path'); - - const filePath = path.resolve(__dirname, '../../'); // this should be the root dir - fs.readdirSync(filePath) // eval all of the js files faking how a browser would execute - .filter(path => { - if (path) { - return /\.js$/.test(path); - } else { - return false; - } - }) - .forEach(file => { - global.eval(fs.readFileSync(`${filePath}/${file}`) + ''); - }); -} - -describe('sayName', function() { - describe('Person', function() { - it('should exist', function() { - expect(Person).toBeDefined(); - }); - it('should be a function', function() { - expect(Person).toEqual(jasmine.any(Function)); - }); - it('should return an object with name and age properties when invoked with new (e.g. var person = new Person(...))', function() { - var person = new Person('Tester', 25); - expect(person.hasOwnProperty('name')).toBe(true); - expect(person.hasOwnProperty('age')).toBe(true); - }); - describe('return object', function() { - it('should be an instance of Person', function() { - var person = new Person('Tester', 25); - var isPerson = person instanceof Person; - expect(isPerson).toBe(true); - }); - it('should have access to a sayName method', function() { - var person = new Person('Tester', 25); - expect(person.sayName).toBeDefined(); - expect(person.sayName).toEqual(jasmine.any(Function)); - }); - describe('sayName', function() { - it('should alert the name of the person on which sayName is invoked', function() { - var tester = new Person('Tester', 25); - var someoneElse = new Person('Simone Elsa', 22); - var alert = spyOn(window, 'alert'); - tester.sayName(); - expect(alert).toHaveBeenCalledWith('Tester'); - someoneElse.sayName(); - expect(alert).toHaveBeenCalledWith('Simone Elsa'); - }); - }); - }); - }); -});