1 /* global describe, it, expect */
3 describe('Number', function () {
6 describe('#toFixed()', function () {
7 it('should convert numbers correctly', function () {
8 expect((0.00008).toFixed(3)).toBe('0.000');
9 expect((0.9).toFixed(0)).toBe('1');
10 expect((1.255).toFixed(2)).toBe('1.25');
11 expect((1843654265.0774949).toFixed(5)).toBe('1843654265.07749');
12 expect((1000000000000000128).toFixed(0)).toBe('1000000000000000128');
16 describe('#toPrecision()', function () {
17 // the spec allows for this test to fail.
18 it('throws a RangeError when < 1 or > 21', function () {
19 expect(function () { return (0.9).toPrecision(0); }).toThrow();
20 // Firefox allows values up to 100
21 expect(function () { return (0.9).toPrecision(101); }).toThrow();
24 it('works as expected', function () {
25 expect((0.00008).toPrecision(3)).toBe('0.0000800');
26 expect((1.255).toPrecision(2)).toBe('1.3');
27 expect((1843654265.0774949).toPrecision(13)).toBe('1843654265.077');
28 expect(NaN.toPrecision(1)).toBe('NaN');
31 it('works with an undefined precision', function () {
33 expect(num.toPrecision()).toBe(String(num));
34 expect(num.toPrecision(undefined)).toBe(String(num));
38 describe('constants', function () {
39 it('should have MAX_VALUE', function () {
40 expect(Number.MAX_VALUE).toBe(1.7976931348623157e308);
43 it('should have MIN_VALUE', function () {
44 expect(Number.MIN_VALUE).toBe(5e-324);
47 it('should have NaN', function () {
48 expect(Number.NaN).not.toBe(Number.NaN);
51 it('should have POSITIVE_INFINITY', function () {
52 expect(Number.POSITIVE_INFINITY).toBe(Infinity);
55 it('should have NEGATIVE_INFINITY', function () {
56 expect(Number.NEGATIVE_INFINITY).toBe(-Infinity);