source: imaps-frontend/node_modules/es-iterator-helpers/test/Iterator.js@ d565449

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

Update repo after prototype presentation

  • Property mode set to 100644
File size: 2.4 KB
Line 
1'use strict';
2
3var defineProperties = require('define-properties');
4var test = require('tape');
5var functionsHaveNames = require('functions-have-names')();
6
7var index = require('../Iterator');
8var impl = require('../Iterator/implementation');
9
10var isEnumerable = Object.prototype.propertyIsEnumerable;
11
12module.exports = {
13 tests: function (Iter, name, t) {
14 t.equal(typeof Iter, 'function', name + ' is a function');
15
16 t['throws'](
17 function () { Iter(); }, // eslint-disable-line new-cap
18 TypeError,
19 name + ' throws when Call-ed'
20 );
21
22 t['throws'](
23 function () { return new Iter(); },
24 TypeError,
25 name + ' throws when Construct-ed'
26 );
27
28 var SubIter;
29 var SubSubIter;
30 try {
31 /* eslint no-new-func: 0 */
32 SubIter = Function('Iter', 'return class SubIter extends Iter {};')(Iter);
33 SubSubIter = Function('SubIter', 'return class SubSubIter extends SubIter {};')(SubIter);
34 } catch (e) { /**/ }
35
36 t.test('class inheritance', { skip: !SubIter }, function (st) {
37 st.doesNotThrow(
38 function () { return new SubIter(); },
39 'Extending ' + name + ' does not throw when Construct-ed'
40 );
41 st.doesNotThrow(
42 function () { return new SubSubIter(); },
43 'Extending ' + name + ' twice does not throw when Construct-ed'
44 );
45
46 st.end();
47 });
48 },
49 index: function () {
50 test('Iterator: index', function (t) {
51 module.exports.tests(index, 'Iterator', t);
52
53 t.end();
54 });
55 },
56 implementation: function () {
57 test('Iterator: implementation', function (t) {
58 module.exports.tests(impl, 'Iterator', t);
59
60 t.end();
61 });
62 },
63 shimmed: function () {
64 test('Iterator: shimmed', function (t) {
65 t.test('Function name', { skip: !functionsHaveNames }, function (st) {
66 st.equal(Iterator.name, 'Iterator', 'Iterator has name "Iterator"');
67 st.end();
68 });
69
70 t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
71 et.equal(false, isEnumerable.call(global, Iterator), 'Iterator is not enumerable');
72 et.end();
73 });
74
75 t.test('prototype descriptor', { skip: !defineProperties.supportsDescriptors }, function (pt) {
76 var desc = Object.getOwnPropertyDescriptor(Iterator, 'prototype');
77 pt.deepEqual(
78 desc,
79 {
80 configurable: false,
81 enumerable: false,
82 value: Iterator.prototype,
83 writable: false
84 }
85 );
86
87 pt.end();
88 });
89
90 module.exports.tests(Iterator, 'Iterator', t);
91
92 t.end();
93 });
94 }
95};
Note: See TracBrowser for help on using the repository browser.