-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removes oopVsFunctionalTests adds .editorconfig file
- Loading branch information
Showing
6 changed files
with
163 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# 4 space indentation | ||
[*.js] | ||
indent_style = space | ||
indent_size = 4 | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
|
||
describe('DAY 8: classes', () => { | ||
|
||
it(`complete the Dog class constructor code to fulfill the test conditions`, () => { | ||
|
||
/** | ||
* | ||
*/ | ||
class Dog { | ||
|
||
/** | ||
* | ||
* @returns {Dog} | ||
*/ | ||
constructor () { | ||
this.favoriteThing = `food`; | ||
} | ||
|
||
} | ||
|
||
let myDog1 = new Dog('fido'); | ||
|
||
expect(myDog1.name).toBe('fido'); | ||
expect(myDog1.favoriteThing).toBe(`food`); | ||
|
||
let myDog2 = new Dog(); | ||
|
||
expect(myDog2.name).toBe(`lonely dog without a name`); | ||
expect(myDog2.favoriteThing).toBe(`food`); | ||
|
||
}); | ||
|
||
it(`Dog should extend from Mammal`, () => { | ||
|
||
/** | ||
* | ||
*/ | ||
class Mammal { | ||
|
||
/** | ||
* @returns { Mammal } | ||
*/ | ||
constructor () { | ||
this.hasFur = true; | ||
this.isWarmBlooded = true; | ||
} | ||
} | ||
|
||
/** | ||
* @extends Mammal | ||
*/ | ||
class Dog { | ||
|
||
/** | ||
* | ||
* @returns {Dog} | ||
*/ | ||
constructor () { | ||
this.favoriteThing = `food`; | ||
} | ||
|
||
} | ||
|
||
let myDog = new Dog(); | ||
|
||
expect(myDog).toBeInstanceOf(Dog); | ||
expect(myDog).toBeInstanceOf(Mammal); | ||
expect(myDog.hasFur).toBe(true); | ||
expect(myDog.favoriteThing).toBe(`food`); | ||
|
||
}); | ||
|
||
it(`Fix the methods of Dog class so that they correctly belong to the "class" or to the "instance"`, () => { | ||
|
||
/** | ||
* | ||
*/ | ||
class Dog { | ||
|
||
/** | ||
* @returns {Dog} | ||
*/ | ||
constructor () { | ||
this.favoriteThing = `food`; | ||
} | ||
|
||
/** | ||
* @returns {string} | ||
*/ | ||
static jump () { | ||
return `jumping`; | ||
} | ||
|
||
/** | ||
* @returns {string} | ||
*/ | ||
bark () { | ||
return `barking`; | ||
} | ||
|
||
} | ||
|
||
let myDog = new Dog(); | ||
|
||
expect(myDog.jump()).toBe('jumping'); | ||
expect(() => myDog.bark()).toThrow('myDog.bark is not a function'); | ||
expect(Dog.bark()).toBe('barking'); | ||
|
||
}); | ||
|
||
it(`use the following code as a starting point | ||
change favoriteThing into a "private" property | ||
add the necessary setter and getter | ||
`, () => { | ||
|
||
/** | ||
* | ||
*/ | ||
class Dog { | ||
|
||
/** | ||
* @returns {Dog} | ||
*/ | ||
constructor () { | ||
this.favoriteThing = `food`; | ||
this[Symbol(`dogName`)] = ''; | ||
} | ||
|
||
/** | ||
* @param {string} name | ||
*/ | ||
set name (name) { | ||
let dogNameSymbol = Object.getOwnPropertySymbols(this)[0]; | ||
this[dogNameSymbol] = name; | ||
} | ||
|
||
/** | ||
* @returns {string} | ||
*/ | ||
get name () { | ||
let dogNameSymbol = Object.getOwnPropertySymbols(this)[0]; | ||
return this[dogNameSymbol]; | ||
} | ||
|
||
} | ||
|
||
let myDog = new Dog(); | ||
myDog.name = `Copernicus`; | ||
myDog.favoriteThing = `eat Aristarchus' food`; | ||
|
||
expect(myDog.name).toBe('Copernicus'); | ||
expect(myDog.favoriteThing).toBe(`eat Aristarchus' food`); | ||
expect(Object.getOwnPropertyNames(myDog)).toEqual([]); | ||
|
||
}); | ||
}); |
Empty file.