Skip to content

Instantly share code, notes, and snippets.

@CooperAtive
Created February 12, 2014 21:56
Show Gist options
  • Save CooperAtive/8965338 to your computer and use it in GitHub Desktop.
Save CooperAtive/8965338 to your computer and use it in GitHub Desktop.
Object Testing
exports.Card = function(suit, rank) {
function contructor() {};
constructor.prototype.getRank = function() { return rank; };
constructor.prototype.getSuit = function() { return suit; };
return new constructor();
};
(function () {
'use strict';
}());
var Card = require('../lib/Card.js').Card,
expect = require('chai').expect;
describe('Card object test:', function() {
var card;
beforeEach( function() {
card = new Card('spades', 'Ace');
});
describe('constructor', function() {
it('Card should be truthy (exists)', function() {
expect(card).to.be.ok;
});
it('getSuit equals the card\'s suit', function() {
expect(Card.getSuit()).to.equal('spades');
});
it('getRank equals the card\'s suit', function() {
expect(Card.getRank()).to.equal('Ace');
});
it('can\'t change the card\'s suit', function() {
card.suit = "Cooper";
expect(card.getSuit()).to.not.equal("Cooper");
});
it('can\'t change the card\'s rank', function() {
card.rank = "Colonel";
expect(card.getSuit()).to.not.equal("Colonel");
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment