Sha256: 6422f5f93d8e75cf977cbc4a882537baedde81e921eddf73e7eef8f0f3a753ed

Contents?: true

Size: 1.81 KB

Versions: 27

Compression:

Stored size: 1.81 KB

Contents

'use strict';

var test = require('tape');
var inspect = require('object-inspect');
var v = require('es-value-fixtures');
var forEach = require('for-each');
var has = require('has');

var shimUnscopables = require('../');

var sortSymbols = function (a, b) {
	return inspect(a).localeCompare(inspect(b));
};

test('shimUnscopables', function (t) {
	t.equal(typeof shimUnscopables, 'function', 'is a function');

	forEach(v.nonStrings, function (notNonEmptyString) {
		t['throws'](
			function () { shimUnscopables(notNonEmptyString); },
			TypeError,
			inspect(notNonEmptyString) + ' is not a non-empty String'
		);
	});

	t['throws'](
		function () { shimUnscopables('x'); },
		TypeError,
		inspect('x') + ' is not on Array.prototype'
	);

	t.test('no symbols', { skip: typeof Symbol === 'function' }, function (st) {
		st.doesNotThrow(function () { shimUnscopables('forEach'); });

		st.end();
	});

	t.test('symbols, no unscopables', { skip: typeof Symbol !== 'function' || Symbol.unscopables }, function (st) {
		st.deepEqual(Object.getOwnPropertySymbols(Array.prototype), [Symbol.iterator]);

		shimUnscopables('forEach');

		st.deepEqual(Object.getOwnPropertySymbols(Array.prototype), [Symbol.iterator]);

		st.end();
	});

	t.test('Symbol.unscopables', { skip: typeof Symbol !== 'function' || !Symbol.unscopables }, function (st) {
		st.deepEqual(
			Object.getOwnPropertySymbols(Array.prototype).sort(sortSymbols),
			[Symbol.iterator, Symbol.unscopables]
		);
		st.notOk(has(Array.prototype[Symbol.unscopables], 'forEach'), 'unscopables map lacks forEach');

		shimUnscopables('forEach');

		st.deepEqual(
			Object.getOwnPropertySymbols(Array.prototype).sort(sortSymbols),
			[Symbol.iterator, Symbol.unscopables]
		);
		st.equal(Array.prototype[Symbol.unscopables].forEach, true, 'unscopables map has forEach');

		st.end();
	});

	t.end();
});

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
immosquare-cleaner-0.1.32 node_modules/es-shim-unscopables/test/index.js
immosquare-cleaner-0.1.31 node_modules/es-shim-unscopables/test/index.js
immosquare-cleaner-0.1.30 node_modules/es-shim-unscopables/test/index.js
immosquare-cleaner-0.1.29 node_modules/es-shim-unscopables/test/index.js
immosquare-cleaner-0.1.28 node_modules/es-shim-unscopables/test/index.js
immosquare-cleaner-0.1.27 node_modules/es-shim-unscopables/test/index.js
immosquare-cleaner-0.1.26 node_modules/es-shim-unscopables/test/index.js
immosquare-cleaner-0.1.25 node_modules/es-shim-unscopables/test/index.js
immosquare-cleaner-0.1.24 node_modules/es-shim-unscopables/test/index.js
immosquare-cleaner-0.1.23 node_modules/es-shim-unscopables/test/index.js
immosquare-cleaner-0.1.22 node_modules/es-shim-unscopables/test/index.js
immosquare-cleaner-0.1.21 node_modules/es-shim-unscopables/test/index.js
immosquare-cleaner-0.1.20 node_modules/es-shim-unscopables/test/index.js
immosquare-cleaner-0.1.19 node_modules/es-shim-unscopables/test/index.js
immosquare-cleaner-0.1.18 node_modules/es-shim-unscopables/test/index.js
immosquare-cleaner-0.1.17 node_modules/es-shim-unscopables/test/index.js
immosquare-cleaner-0.1.16 node_modules/es-shim-unscopables/test/index.js
immosquare-cleaner-0.1.14 node_modules/es-shim-unscopables/test/index.js
immosquare-cleaner-0.1.13 node_modules/es-shim-unscopables/test/index.js
immosquare-cleaner-0.1.12 node_modules/es-shim-unscopables/test/index.js