forked from zloirock/core-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathes.number.to-fixed.js
70 lines (70 loc) · 3.7 KB
/
es.number.to-fixed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* eslint-disable unicorn/require-number-to-fixed-digits-argument -- required for testing */
QUnit.test('Number#toFixed', assert => {
const { toFixed } = Number.prototype;
assert.isFunction(toFixed);
assert.name(toFixed, 'toFixed');
assert.arity(toFixed, 1);
assert.looksNative(toFixed);
assert.nonEnumerable(Number.prototype, 'toFixed');
assert.same(0.00008.toFixed(3), '0.000');
assert.same(0.9.toFixed(0), '1');
assert.same(1.255.toFixed(2), '1.25');
assert.same(1843654265.0774949.toFixed(5), '1843654265.07749');
assert.same(1000000000000000128.0.toFixed(0), '1000000000000000128');
assert.same(toFixed.call(1), '1');
assert.same(toFixed.call(1, 0), '1');
assert.same(toFixed.call(1, 1), '1.0');
assert.same(toFixed.call(1, 1.1), '1.0');
assert.same(toFixed.call(1, 0.9), '1');
assert.same(toFixed.call(1, '0'), '1');
assert.same(toFixed.call(1, '1'), '1.0');
assert.same(toFixed.call(1, '1.1'), '1.0');
assert.same(toFixed.call(1, '0.9'), '1');
assert.same(toFixed.call(1, NaN), '1');
assert.same(toFixed.call(1, 'some string'), '1');
assert.notThrows(() => toFixed.call(1, -0.1) === '1');
assert.same(new Number(1).toFixed(), '1');
assert.same(new Number(1).toFixed(0), '1');
assert.same(new Number(1).toFixed(1), '1.0');
assert.same(new Number(1).toFixed(1.1), '1.0');
assert.same(new Number(1).toFixed(0.9), '1');
assert.same(new Number(1).toFixed('0'), '1');
assert.same(new Number(1).toFixed('1'), '1.0');
assert.same(new Number(1).toFixed('1.1'), '1.0');
assert.same(new Number(1).toFixed('0.9'), '1');
assert.same(new Number(1).toFixed(NaN), '1');
assert.same(new Number(1).toFixed('some string'), '1');
assert.notThrows(() => new Number(1).toFixed(-0.1) === '1');
assert.same(NaN.toFixed(), 'NaN');
assert.same(NaN.toFixed(0), 'NaN');
assert.same(NaN.toFixed(1), 'NaN');
assert.same(NaN.toFixed(1.1), 'NaN');
assert.same(NaN.toFixed(0.9), 'NaN');
assert.same(NaN.toFixed('0'), 'NaN');
assert.same(NaN.toFixed('1'), 'NaN');
assert.same(NaN.toFixed('1.1'), 'NaN');
assert.same(NaN.toFixed('0.9'), 'NaN');
assert.same(NaN.toFixed(NaN), 'NaN');
assert.same(NaN.toFixed('some string'), 'NaN');
assert.notThrows(() => NaN.toFixed(-0.1) === 'NaN');
assert.same(new Number(1e21).toFixed(), String(1e21));
assert.same(new Number(1e21).toFixed(0), String(1e21));
assert.same(new Number(1e21).toFixed(1), String(1e21));
assert.same(new Number(1e21).toFixed(1.1), String(1e21));
assert.same(new Number(1e21).toFixed(0.9), String(1e21));
assert.same(new Number(1e21).toFixed('0'), String(1e21));
assert.same(new Number(1e21).toFixed('1'), String(1e21));
assert.same(new Number(1e21).toFixed('1.1'), String(1e21));
assert.same(new Number(1e21).toFixed('0.9'), String(1e21));
assert.same(new Number(1e21).toFixed(NaN), String(1e21));
assert.same(new Number(1e21).toFixed('some string'), String(1e21));
assert.notThrows(() => new Number(1e21).toFixed(-0.1) === String(1e21));
assert.throws(() => 1.0.toFixed(-101), RangeError, 'If f < 0 or f > 20 (100), throw a RangeError exception.');
assert.throws(() => 1.0.toFixed(101), RangeError, 'If f < 0 or f > 20 (100), throw a RangeError exception.');
assert.throws(() => NaN.toFixed(Infinity), RangeError, 'If f < 0 or f > 20 (100), throw a RangeError exception.');
assert.throws(() => toFixed.call({}, 1), TypeError, '? thisNumberValue(this value)');
assert.throws(() => toFixed.call('123', 1), TypeError, '? thisNumberValue(this value)');
assert.throws(() => toFixed.call(false, 1), TypeError, '? thisNumberValue(this value)');
assert.throws(() => toFixed.call(null, 1), TypeError, '? thisNumberValue(this value)');
assert.throws(() => toFixed.call(undefined, 1), TypeError, '? thisNumberValue(this value)');
});