Skip to content

Instantly share code, notes, and snippets.

@bnoden
Created May 22, 2018 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bnoden/1280c393c470e1f8761f209e2d7eca6c to your computer and use it in GitHub Desktop.
Save bnoden/1280c393c470e1f8761f209e2d7eca6c to your computer and use it in GitHub Desktop.
Car Composition Tests
const { movement } = require('./props');
const { park, drive } = movement;
module.exports = {
movement: {
park,
drive
}
};
{
"scripts": {
"test": "mocha"
},
"dependencies": {
"mocha": "^5.2.0"
}
}
const movement = {
park: 'stopped',
drive: 'vroom',
fly: 'phewww'
};
const projectile = {
fire: 'burn',
laser: 'beam',
antimatter: 'begone'
};
module.exports = { movement, projectile };
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