From b9f795134d6fce1079502eddf92629d818d97499 Mon Sep 17 00:00:00 2001 From: Sarbbottam Bandyopadhyay Date: Sun, 23 Aug 2015 23:32:21 -0700 Subject: [PATCH] added method to disable the SlotMachine this method would remove the event listener from the start button this method would be helpful if the consumer want to use the same markup for a different slot machine. --- src/slot-machine.js | 8 ++++++++ test/slot-machine.js | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/src/slot-machine.js b/src/slot-machine.js index 2325ffa..b7dc65b 100644 --- a/src/slot-machine.js +++ b/src/slot-machine.js @@ -275,6 +275,14 @@ function SlotMachine(config) { this.startButton.addEventListener('click', start); }; + /** + * @function disable + * disable the instance of a SlotMachine + */ + this.disable = function() { + this.startButton.removeEventListener('click', start); + }; + } module.exports = SlotMachine; diff --git a/test/slot-machine.js b/test/slot-machine.js index 28e89b8..1d4c201 100644 --- a/test/slot-machine.js +++ b/test/slot-machine.js @@ -248,6 +248,12 @@ describe('SlotMachine', function() { }, 5000); }); + it('should disable the slotMachine', function() { + var spy = sinon.spy(slotMachine, 'disable'); + slotMachine.disable(); + assert.isTrue(spy.called); + }); + // it('should result in Jackpot, for tea', function(done) { // this.timeout(10000); // slotMachine.reels.forEach(function(reel) {