UNPKG

card-decks

Version:

A module to simulate one to n decks of cards.

97 lines (82 loc) 2.87 kB
'use strict'; let chai = require('chai'); let expect = chai.expect; let _ = require('lodash'); let assert = chai.assert; let Card = require('../src').Card; describe('Card', () => { describe('Card Constructor', () => { it('Should throw BAD_INIT if not passed an object with suit and rank properties', () => { // No object expect(() => new Card()).to.throw(Card.BAD_INIT); // Only suit let obj = { 'suit': Card.SUITS.HEARTS }; expect(() => new Card(obj)).to.throw(Card.BAD_INIT); // Only rank obj = { 'rank': Card.RANKS.FIVE }; expect(() => new Card(obj)).to.throw(Card.BAD_INIT); }); it ('Should throw BAD_COMBO if object passed is invalid', () => { // Bad suit let obj = { 'suit': 'asdfs', 'rank': Card.RANKS.TWO }; expect(() => new Card(obj)).to.throw(Card.BAD_COMBO); // Bad rank obj = { 'suit': Card.SUITS.HEARTS, 'rank': '34234' }; expect(() => new Card(obj)).to.throw(Card.BAD_COMBO); // both bad obj = { 'suit': 'hello', 'rank': '34234' }; expect(() => new Card(obj)).to.throw(Card.BAD_COMBO); }); it ('Should validate and assign the suit and rank passed', () => { // Iterate over ranks _.forEach(Card.Combinations, (obj) => { let card = new Card(obj); expect(card.suit).to.equal(obj.suit); expect(card.rank).to.equal(obj.rank); }); }); }); describe('getSuit()', () => { it('Should return the correct suit', () => { let obj = { 'suit': Card.SUITS.HEARTS, 'rank': Card.RANKS.TWO }; let card = new Card(obj); expect(card.getSuit()).to.equal(obj.suit); }); }); describe('getRank()', () => { it('Should return the correct rank', () => { let obj = { 'suit': Card.SUITS.HEARTS, 'rank': Card.RANKS.TWO }; let card = new Card(obj); expect(card.getRank()).to.equal(obj.rank); }); }); describe('getCombo()', () => { it('Should return the correct combo', () => { let obj = { 'suit': Card.SUITS.HEARTS, 'rank': Card.RANKS.TWO }; let card = new Card(obj); assert(_.isEqual(card.getCombo(), obj)); }) }); });