source: imaps-frontend/node_modules/es-shim-unscopables/test/index.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.8 KB
Line 
1'use strict';
2
3var test = require('tape');
4var inspect = require('object-inspect');
5var v = require('es-value-fixtures');
6var forEach = require('for-each');
7var hasOwn = require('hasown');
8
9var shimUnscopables = require('../');
10
11var sortSymbols = function (a, b) {
12 return inspect(a).localeCompare(inspect(b));
13};
14
15test('shimUnscopables', function (t) {
16 t.equal(typeof shimUnscopables, 'function', 'is a function');
17
18 forEach(v.nonStrings, function (notNonEmptyString) {
19 t['throws'](
20 function () { shimUnscopables(notNonEmptyString); },
21 TypeError,
22 inspect(notNonEmptyString) + ' is not a non-empty String'
23 );
24 });
25
26 t['throws'](
27 function () { shimUnscopables('x'); },
28 TypeError,
29 inspect('x') + ' is not on Array.prototype'
30 );
31
32 t.test('no symbols', { skip: typeof Symbol === 'function' }, function (st) {
33 st.doesNotThrow(function () { shimUnscopables('forEach'); });
34
35 st.end();
36 });
37
38 t.test('symbols, no unscopables', { skip: typeof Symbol !== 'function' || Symbol.unscopables }, function (st) {
39 st.deepEqual(Object.getOwnPropertySymbols(Array.prototype), [Symbol.iterator]);
40
41 shimUnscopables('forEach');
42
43 st.deepEqual(Object.getOwnPropertySymbols(Array.prototype), [Symbol.iterator]);
44
45 st.end();
46 });
47
48 t.test('Symbol.unscopables', { skip: typeof Symbol !== 'function' || !Symbol.unscopables }, function (st) {
49 st.deepEqual(
50 Object.getOwnPropertySymbols(Array.prototype).sort(sortSymbols),
51 [Symbol.iterator, Symbol.unscopables]
52 );
53 st.notOk(hasOwn(Array.prototype[Symbol.unscopables], 'forEach'), 'unscopables map lacks forEach');
54
55 shimUnscopables('forEach');
56
57 st.deepEqual(
58 Object.getOwnPropertySymbols(Array.prototype).sort(sortSymbols),
59 [Symbol.iterator, Symbol.unscopables]
60 );
61 st.equal(Array.prototype[Symbol.unscopables].forEach, true, 'unscopables map has forEach');
62
63 st.end();
64 });
65
66 t.end();
67});
Note: See TracBrowser for help on using the repository browser.