Created
May 22, 2018 02:22
-
-
Save bnoden/1280c393c470e1f8761f209e2d7eca6c to your computer and use it in GitHub Desktop.
Car Composition Tests
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
const { movement } = require('./props'); | |
const { park, drive } = movement; | |
module.exports = { | |
movement: { | |
park, | |
drive | |
} | |
}; |
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
{ | |
"scripts": { | |
"test": "mocha" | |
}, | |
"dependencies": { | |
"mocha": "^5.2.0" | |
} | |
} |
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
const movement = { | |
park: 'stopped', | |
drive: 'vroom', | |
fly: 'phewww' | |
}; | |
const projectile = { | |
fire: 'burn', | |
laser: 'beam', | |
antimatter: 'begone' | |
}; | |
module.exports = { movement, projectile }; |
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
const assert = require('assert'); | |
const Car = require('./Car'); | |
const { movement, projectile } = require('./props'); | |
const { park, drive, fly } = movement; | |
const { fire, laser, antimatter } = projectile; | |
//////////////////////////////////////////////////////////////// | |
beforeEach(() => { | |
car = Object.assign({}, Car); | |
}); | |
describe('Car', () => { | |
it('can move', () => { | |
assert.equal(Object.getOwnPropertyNames(car).includes('movement'), true); | |
}); | |
it('can park by default', () => { | |
assert.equal(car.movement.park, 'stopped'); | |
}); | |
it('can drive by default', () => { | |
assert.equal(car.movement.drive, 'vroom'); | |
}); | |
it('cannot fly by default', () => { | |
assert.notEqual(car.movement.fly, 'phewww'); | |
}); | |
it('can fly', () => { | |
car.movement.fly = fly; | |
assert.equal(car.movement.fly, 'phewww'); | |
}); | |
it('cannot shoot by default', () => { | |
assert.equal(Object.getOwnPropertyNames(car).includes('projectile'), false); | |
}); | |
it('can shoot', () => { | |
car.projectile = projectile; | |
assert.equal(Object.getOwnPropertyNames(car).includes('projectile'), true); | |
}); | |
it('can shoot lasers only', () => { | |
car = { ...Car, projectile: { laser } }; | |
assert.equal(Object.values(car.projectile).join(' '), 'beam'); | |
}); | |
it('can shoot fire, lasers, and anti-matter', () => { | |
car.projectile = projectile; | |
assert.equal(Object.values(car.projectile).join(' '), 'burn beam begone'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment