Skip to content

Commit

Permalink
adds Classes tests
Browse files Browse the repository at this point in the history
removes oopVsFunctionalTests
adds .editorconfig file
  • Loading branch information
Jaxolotl committed Oct 9, 2019
1 parent 9dafbe6 commit dc37d33
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
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
1 change: 0 additions & 1 deletion day_08.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ let plantsWithMoreFlowers = myPlants.map(flower => ++flower);
Let's open our test files:

- [Classes](/src/day_08/classes.test.js)
- [oop vs functional](/src/day_08/oopVsFunctional.test.js)

Now open your terminal.

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "a-walk-in-javascript",
"version": "1.8.1",
"version": "1.9.0",
"description": "A day by day walk through the basics of javascript assisted with notes, exercises and references to the most significant resources online",
"main": "''",
"scripts": {
Expand Down
156 changes: 156 additions & 0 deletions src/day_08/classes.test.js
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 removed src/day_08/oopVsFunctional.test.js
Empty file.

0 comments on commit dc37d33

Please sign in to comment.