-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
es.number.to-fixed.js
66 lines (65 loc) · 3.25 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
import toFixed from 'core-js-pure/es/number/to-fixed';
QUnit.test('Number#toFixed', assert => {
assert.isFunction(toFixed);
assert.same(toFixed(0.00008, 3), '0.000');
assert.same(toFixed(0.9, 0), '1');
assert.same(toFixed(1.255, 2), '1.25');
assert.same(toFixed(1843654265.0774949, 5), '1843654265.07749');
assert.same(toFixed(1000000000000000128, 0), '1000000000000000128');
assert.same(toFixed(1), '1');
assert.same(toFixed(1, 0), '1');
assert.same(toFixed(1, 1), '1.0');
assert.same(toFixed(1, 1.1), '1.0');
assert.same(toFixed(1, 0.9), '1');
assert.same(toFixed(1, '0'), '1');
assert.same(toFixed(1, '1'), '1.0');
assert.same(toFixed(1, '1.1'), '1.0');
assert.same(toFixed(1, '0.9'), '1');
assert.same(toFixed(1, NaN), '1');
assert.same(toFixed(1, 'some string'), '1');
assert.notThrows(() => toFixed(1, -0.1) === '1');
assert.same(toFixed(Object(1)), '1');
assert.same(toFixed(Object(1), 0), '1');
assert.same(toFixed(Object(1), 1), '1.0');
assert.same(toFixed(Object(1), 1.1), '1.0');
assert.same(toFixed(Object(1), 0.9), '1');
assert.same(toFixed(Object(1), '0'), '1');
assert.same(toFixed(Object(1), '1'), '1.0');
assert.same(toFixed(Object(1), '1.1'), '1.0');
assert.same(toFixed(Object(1), '0.9'), '1');
assert.same(toFixed(Object(1), NaN), '1');
assert.same(toFixed(Object(1), 'some string'), '1');
assert.notThrows(() => toFixed(Object(1), -0.1) === '1');
assert.same(toFixed(NaN), 'NaN');
assert.same(toFixed(NaN, 0), 'NaN');
assert.same(toFixed(NaN, 1), 'NaN');
assert.same(toFixed(NaN, 1.1), 'NaN');
assert.same(toFixed(NaN, 0.9), 'NaN');
assert.same(toFixed(NaN, '0'), 'NaN');
assert.same(toFixed(NaN, '1'), 'NaN');
assert.same(toFixed(NaN, '1.1'), 'NaN');
assert.same(toFixed(NaN, '0.9'), 'NaN');
assert.same(toFixed(NaN, NaN), 'NaN');
assert.same(toFixed(NaN, 'some string'), 'NaN');
assert.notThrows(() => toFixed(NaN, -0.1) === 'NaN');
assert.same(toFixed(1e21), String(1e21));
assert.same(toFixed(1e21, 0), String(1e21));
assert.same(toFixed(1e21, 1), String(1e21));
assert.same(toFixed(1e21, 1.1), String(1e21));
assert.same(toFixed(1e21, 0.9), String(1e21));
assert.same(toFixed(1e21, '0'), String(1e21));
assert.same(toFixed(1e21, '1'), String(1e21));
assert.same(toFixed(1e21, '1.1'), String(1e21));
assert.same(toFixed(1e21, '0.9'), String(1e21));
assert.same(toFixed(1e21, NaN), String(1e21));
assert.same(toFixed(1e21, 'some string'), String(1e21));
assert.notThrows(() => toFixed(1e21, -0.1) === String(1e21));
assert.throws(() => toFixed(1, -101), RangeError, 'If f < 0 or f > 20 (100), throw a RangeError exception.');
assert.throws(() => toFixed(1, 101), RangeError, 'If f < 0 or f > 20 (100), throw a RangeError exception.');
assert.throws(() => toFixed(NaN, Infinity), RangeError, 'If f < 0 or f > 20 (100), throw a RangeError exception.');
assert.throws(() => toFixed({}, 1), TypeError, '? thisNumberValue(this value)');
assert.throws(() => toFixed('123', 1), TypeError, '? thisNumberValue(this value)');
assert.throws(() => toFixed(false, 1), TypeError, '? thisNumberValue(this value)');
assert.throws(() => toFixed(null, 1), TypeError, '? thisNumberValue(this value)');
assert.throws(() => toFixed(undefined, 1), TypeError, '? thisNumberValue(this value)');
});