Numeraljs format test

forked from http://jsfiddle.net/opensas/3VuGs/

HTML

<link rel="stylesheet" href="//cdn.jsdelivr.net/jasmine/1.3.1/jasmine.css">
<script src="//cdn.jsdelivr.net/jasmine/1.3.1/jasmine.js"></script>
<script src="//cdn.jsdelivr.net/jasmine/1.3.1/jasmine-html.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/numeral.js/1.5.3/numeral.min.js"></script>
<title>Jasmine Spec Runner</title>

JavaScript

/*
This sample js snippet shows how to run a simple jasmine test inside jsFiddle.

To make your tests pass, just comment out the line 15, uncomment the line 16 and press ctrl-enter to run the test.

For more info check: http://opensas.wordpress.com/2013/06/23/sharing-you-javascript-ninja-secrets-run-your-jasmine-tests-on-jsfiddle/
*/

/*
Assignment: implement the calculator.sum method so that it takes two parameters and returns the sum of them.
*/

// source code
var numeralFormat = {
    format: function (number, format) {
        return numeral(number).format(format);
    }
};

// specs code
describe("numeralFormat", function () {

    it("should format to a rounded whole number", function () {
        expect(numeralFormat.format(1234.567, "0,0")).toEqual("1,235");
    });

    it("should format to a rounded decimal number", function () {
        expect(numeralFormat.format(1234.567, "0,0.00")).toEqual("1,234.57");
    });

    it("should format to always display 2 decimal digits", function () {
        expect(numeralFormat.format(1234, "0,0.00")).toEqual("1,234.00");
    });

    var formatForBothWholeAndDecimal = "0,0.99";
    
    it("should not show decimal digits when value is a whole number", function () {
        expect(numeralFormat.format(1234, formatForBothWholeAndDecimal)).toEqual("1,234");
    });

    it("should show decimal digits as needed", function () {
        expect(numeralFormat.format(1234.567, formatForBothWholeAndDecimal)).toEqual("1,234.57");
    });

});

var NOT_IMPLEMENTED = undefined;

// load jasmine htmlReporter
(function () {
    var env = jasmine.getEnv();
    env.addReporter(new jasmine.HtmlReporter());
    env.execute();
}());