Last active
July 11, 2017 17:18
-
-
Save tmlbl/8963534 to your computer and use it in GitHub Desktop.
A Simple OOP-Type Object and Mocha Test
This file contains hidden or 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
var Card = function (suit, rank) { | |
function constructor () { } | |
constructor.prototype.getSuit = function () { | |
return suit; | |
}; | |
constructor.prototype.setSuit = function (s) { | |
suit = s; | |
}; | |
constructor.prototype.getRank = function () { | |
return rank; | |
}; | |
constructor.prototype.setRank = function (r) { | |
rank = r; | |
}; | |
return new constructor(); | |
}; | |
exports.Card = Card; |
This file contains hidden or 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
var expect = require('chai').expect, | |
Card = require('../card.js').Card; | |
describe('Card:', function () { | |
'use strict'; | |
var card; | |
beforeEach(function () { | |
card = new Card('Diamonds', 8); | |
}); | |
describe('Constructor:', function () { | |
it('Should be truthy', function () { | |
expect(card).to.be.a('object'); | |
}); | |
it('Should have a settable suit', function () { | |
card.setSuit('Hearts'); | |
expect(card.getSuit()).to.equal('Hearts'); | |
}); | |
it('Should have a settable rank', function () { | |
card.setRank('9'); | |
expect(card.getRank()).to.equal('9'); | |
}); | |
it('Should be immutable', function () { | |
card.suit = 'Hearts'; | |
expect(card.getSuit()).to.equal('Diamonds'); | |
}); | |
}); | |
}); |
This file contains hidden or 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
Running "simplemocha:all" (simplemocha) task | |
1..4 | |
ok 1 Card: Constructor: Should be truthy | |
ok 2 Card: Constructor: Should have a settable suit | |
ok 3 Card: Constructor: Should have a settable rank | |
ok 4 Card: Constructor: Should be immutable | |
# tests 4 | |
# pass 4 | |
# fail 0 | |
Running "jshint:myFiles" (jshint) task | |
>> 2 files lint free. | |
Done, without errors. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment