Fixes failing unit tests on IE11/Edge

This commit is contained in:
jos 2018-06-04 21:19:10 +02:00
parent 33a7c0b739
commit ee008d992e
5 changed files with 44 additions and 7 deletions

View File

@ -3,6 +3,9 @@
var deepMap = require('../../utils/collection/deepMap');
var number = require('../../utils/number');
// Number.isNaN is more robust than isNaN, but Number.isNaN is not available for example on IE11
var _isNaN = Number.isNaN || isNaN;
function factory (type, config, load, typed) {
/**
* Test whether a value is NaN (not a number).
@ -35,7 +38,7 @@ function factory (type, config, load, typed) {
*/
var isNaN = typed('isNaN', {
'number': function (x) {
return Number.isNaN(x);
return _isNaN(x);
},
'BigNumber': function (x) {
@ -51,11 +54,11 @@ function factory (type, config, load, typed) {
},
'Unit': function (x) {
return Number.isNaN(x.value);
return _isNaN(x.value);
},
'Array | Matrix': function (x) {
return deepMap(x, Number.isNaN);
return deepMap(x, _isNaN);
}
});

View File

@ -262,3 +262,35 @@ exports.hasOwnProperty = function (object, property) {
exports.isFactory = function (object) {
return object && typeof object.factory === 'function';
};
// Polyfill for Object.assign for IE 11 (Object.assign is used in `escape-latex`)
// Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
if (typeof Object.assign !== 'function') {
// Must be writable: true, enumerable: false, configurable: true
Object.defineProperty(Object, "assign", {
value: function assign(target, varArgs) { // .length of function is 2
'use strict';
if (target == null) { // TypeError if undefined or null
throw new TypeError('Cannot convert undefined or null to object');
}
var to = Object(target);
for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
if (nextSource != null) { // Skip over if undefined or null
for (var nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
},
writable: true,
configurable: true
});
}

View File

@ -33,8 +33,10 @@ describe('sinh', function() {
it('should return the sinh of very small numbers (avoid returning zero)', function() {
// If sinh returns 0, that is bad, so we are using assert.equal, not approx.equal
assert.equal(sinh(-1e-10), -1e-10);
assert.equal(sinh(1e-50), 1e-50);
assert(sinh(-1e-10) !== 0);
assert(sinh(-1e-50) !== 0);
assert(Math.abs(sinh(-1e-10) - -1e-10) < EPSILON);
assert(Math.abs(sinh(1e-50) - 1e-50) < EPSILON);
});
}

View File

@ -152,7 +152,7 @@ describe('range', function() {
it('should stringify a range to format start:step:end with given precision', function () {
assert.equal(new math.type.Range(1/3, 4/3, 2/3).format(3), '0.333:0.667:1.33');
assert.equal(new math.type.Range(1/3, 4/3, 2/3).format(4), '0.3333:0.6667:1.333');
assert.equal(new math.type.Range(1/3, 4/3, 2/3).format(), '0.3333333333333333:0.6666666666666666:1.3333333333333333');
assert.equal(new math.type.Range(1/3, 4/3, 2/3).format(14), '0.33333333333333:0.66666666666667:1.3333333333333');
});
});

View File

@ -17,7 +17,7 @@ describe('physical constants', function() {
assert.equal(math.magneticConstant.toString(), '1.2566370614e-6 N / A^2');
assert.equal(math.electricConstant.toString(), '8.854187817e-12 F / m');
assert.equal(math.vacuumImpedance.toString(), '376.730313461 ohm');
assert.equal(math.coulomb.toString(), '8.987551787368176e+9 (N m^2) / C^2');
assert.equal(math.coulomb.format({precision: 14}), '8.9875517873682e+9 (N m^2) / C^2'); // round off issues on IE11 if not using precisions
assert.equal(math.elementaryCharge.toString(), '1.60217656535e-19 C');
assert.equal(math.bohrMagneton.toString(), '9.274009682e-24 J / T');
assert.equal(math.conductanceQuantum.toString(), '7.748091734625e-5 S');