source: trip-planner-front/node_modules/object.assign/test/shimmed.js@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.9 KB
Line 
1'use strict';
2
3var assign = require('../');
4assign.shim();
5
6var test = require('tape');
7var defineProperties = require('define-properties');
8var isEnumerable = Object.prototype.propertyIsEnumerable;
9var functionsHaveNames = require('functions-have-names')();
10
11var runTests = require('./tests');
12
13test('shimmed', function (t) {
14 t.equal(Object.assign.length, 2, 'Object.assign has a length of 2');
15 t.test('Function name', { skip: !functionsHaveNames }, function (st) {
16 st.equal(Object.assign.name, 'assign', 'Object.assign has name "assign"');
17 st.end();
18 });
19
20 t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
21 et.equal(false, isEnumerable.call(Object, 'assign'), 'Object.assign is not enumerable');
22 et.end();
23 });
24
25 var supportsStrictMode = (function () { return typeof this === 'undefined'; }());
26
27 t.test('bad object value', { skip: !supportsStrictMode }, function (st) {
28 st['throws'](function () { return Object.assign(undefined); }, TypeError, 'undefined is not an object');
29 st['throws'](function () { return Object.assign(null); }, TypeError, 'null is not an object');
30 st.end();
31 });
32
33 // v8 in node 0.8 and 0.10 have non-enumerable string properties
34 var stringCharsAreEnumerable = isEnumerable.call('xy', 0);
35 t.test('when Object.assign is present and has pending exceptions', { skip: !stringCharsAreEnumerable || !Object.preventExtensions }, function (st) {
36 /*
37 * Firefox 37 still has "pending exception" logic in its Object.assign implementation,
38 * which is 72% slower than our shim, and Firefox 40's native implementation.
39 */
40 var thrower = Object.preventExtensions({ 1: '2' });
41 var error;
42 try { Object.assign(thrower, 'xy'); } catch (e) { error = e; }
43 st.equal(error instanceof TypeError, true, 'error is TypeError');
44 st.equal(thrower[1], '2', 'thrower[1] === "2"');
45
46 st.end();
47 });
48
49 runTests(Object.assign, t);
50
51 t.end();
52});
Note: See TracBrowser for help on using the repository browser.