diff --git a/README.md b/README.md index 1511bfb15..c0b447891 100755 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ Inferno v9 requires following features to be present in the executing runtime: - `String.prototype.startsWith()` - `Array.prototype.includes()` - `Object.spread()` +- `for ... of` ## Browser support Since version 4 we have started running our test suite **without** any polyfills. diff --git a/docs/animations/app.js b/docs/animations/app.js index 869836c19..b0a9b4250 100644 --- a/docs/animations/app.js +++ b/docs/animations/app.js @@ -604,9 +604,9 @@ class ShuffleListWithAnimation extends Component { doClearMarkers = (e) => { e && e.preventDefault(); const tmp = document.querySelectorAll('.debugMarker'); - tmp.forEach((marker) => { + for (const marker of tmp) { marker.parentNode.removeChild(marker); - }); + } }; componentDidMount() { diff --git a/fixtures/packaging/build-all.js b/fixtures/packaging/build-all.js index 74247087d..c1eebff53 100644 --- a/fixtures/packaging/build-all.js +++ b/fixtures/packaging/build-all.js @@ -54,7 +54,7 @@ function buildFixture(tool, environment) { }; } -fixtureDirs.forEach((dir) => { +for (const dir of fixtureDirs) { const devPath = path.join(__dirname, dir, 'dev'); if (existsSync(devPath)) { addResult(dir, 'dev', buildFixture(dir, 'dev')); @@ -63,6 +63,6 @@ fixtureDirs.forEach((dir) => { if (existsSync(prodPath)) { addResult(dir, 'prod', buildFixture(dir, 'prod')); } -}); +} console.log(table.toString()); diff --git a/packages/inferno-clone-vnode/__tests__/cloneVNode.spec.tsx b/packages/inferno-clone-vnode/__tests__/cloneVNode.spec.tsx index 4e9e97602..51a46aebe 100644 --- a/packages/inferno-clone-vnode/__tests__/cloneVNode.spec.tsx +++ b/packages/inferno-clone-vnode/__tests__/cloneVNode.spec.tsx @@ -619,7 +619,10 @@ the clone
A child that should render after t public render() { const content: NormalItem[] = [, ]; - items.forEach((_d, idx) => content.push()); + for (const _d of items) { + const idx = items.indexOf(_d); + content.push(); + } return ( diff --git a/packages/inferno-compat/__tests__/ReactChildren.spec.jsx b/packages/inferno-compat/__tests__/ReactChildren.spec.jsx index 7ba17d685..065928fa3 100644 --- a/packages/inferno-compat/__tests__/ReactChildren.spec.jsx +++ b/packages/inferno-compat/__tests__/ReactChildren.spec.jsx @@ -120,185 +120,6 @@ describe('ReactChildren', function () { expect(React.Children.forEach(null, null, null)).toBe(undefined); }); - // it('should be called for each child', function() { - // var zero =
; - // var one = null; - // var two =
; - // var three = null; - // var four =
; - // - // var zeroMapped =
; // Key should be joined to obj key - // var oneMapped = null; // Key should be added even if we don't supply it! - // var twoMapped =
; // Key should be added even if not supplied! - // var threeMapped = ; // Map from null to something. - // var fourMapped =
; - // - // var callback = jasmine.createSpy().and.callFake(function(kid, index) { - // return index === 0 ? zeroMapped : - // index === 1 ? oneMapped : - // index === 2 ? twoMapped : - // index === 3 ? threeMapped : fourMapped; - // }); - // var instance = ( - //
- // {zero} - // {one} - // {two} - // {three} - // {four} - //
- // ); - // - // ReactChildren.forEach(instance.children, callback); - // expect(callback).toHaveBeenCalledWith(zero, 0); - // expect(callback).toHaveBeenCalledWith(one, 1); - // expect(callback).toHaveBeenCalledWith(two, 2); - // expect(callback).toHaveBeenCalledWith(three, 3); - // expect(callback).toHaveBeenCalledWith(four, 4); - // callback.calls.calls.reset(); - // - // var mappedChildren = - // ReactChildren.map(instance.children, callback); - // expect(callback.calls.count()).toBe(5); - // expect(ReactChildren.count(mappedChildren)).toBe(4); - // // Keys default to indices. - // expect([ - // mappedChildren[0].key, - // mappedChildren[1].key, - // mappedChildren[2].key, - // mappedChildren[3].key, - // ]).toEqual( - // ['giraffe/.$keyZero', '/.$keyTwo', '/.3', 'keyFour/.$keyFour'] - // ); - // - // expect(callback).toHaveBeenCalledWith(zero, 0); - // expect(callback).toHaveBeenCalledWith(one, 1); - // expect(callback).toHaveBeenCalledWith(two, 2); - // expect(callback).toHaveBeenCalledWith(three, 3); - // expect(callback).toHaveBeenCalledWith(four, 4); - // - // expect(mappedChildren[0]).toEqual(
); - // expect(mappedChildren[1]).toEqual(
); - // expect(mappedChildren[2]).toEqual(); - // expect(mappedChildren[3]).toEqual(
); - // }); - - // it('should be called for each child in nested structure', function() { - // var zero =
; - // var one = null; - // var two =
; - // var three = null; - // var four =
; - // var five =
; - // // five is placed into a JS object with a key that is joined to the - // // component key attribute. - // // Precedence is as follows: - // // 1. If grouped in an Object, the object key combined with `key` prop - // // 2. If grouped in an Array, the `key` prop, falling back to array index - - // var zeroMapped =
; // Key should be overridden - // var twoMapped =
; // Key should be added even if not supplied! - // var fourMapped =
; - // var fiveMapped =
; - - // var callback = jasmine.createSpy().and.callFake(function(kid, index) { - // return index === 0 ? zeroMapped : - // index === 1 ? twoMapped : - // index === 2 ? fourMapped : fiveMapped; - // }); - - // var frag = ReactFragment.create({ - // firstHalfKey: [zero, one, two], - // secondHalfKey: [three, four], - // keyFive: five, - // }); - // var instance =
{[frag]}
; - - // expect([ - // frag[0].key, - // frag[1].key, - // frag[2].key, - // frag[3].key, - // ]).toEqual([ - // 'firstHalfKey/.$keyZero', - // 'firstHalfKey/.$keyTwo', - // 'secondHalfKey/.$keyFour', - // 'keyFive/.$keyFiveInner', - // ]); - - // ReactChildren.forEach(instance.props.children, callback); - // expect(callback.calls.count()).toBe(4); - // expect(callback).toHaveBeenCalledWith(frag[0], 0); - // expect(callback).toHaveBeenCalledWith(frag[1], 1); - // expect(callback).toHaveBeenCalledWith(frag[2], 2); - // expect(callback).toHaveBeenCalledWith(frag[3], 3); - // callback.calls.calls.reset(); - - // var mappedChildren = ReactChildren.map(instance.props.children, callback); - // expect(callback.calls.count()).toBe(4); - // expect(callback).toHaveBeenCalledWith(frag[0], 0); - // expect(callback).toHaveBeenCalledWith(frag[1], 1); - // expect(callback).toHaveBeenCalledWith(frag[2], 2); - // expect(callback).toHaveBeenCalledWith(frag[3], 3); - - // expect(ReactChildren.count(mappedChildren)).toBe(4); - // // Keys default to indices. - // expect([ - // mappedChildren[0].key, - // mappedChildren[1].key, - // mappedChildren[2].key, - // mappedChildren[3].key, - // ]).toEqual([ - // 'giraffe/.0:$firstHalfKey/=1$keyZero', - // '/.0:$firstHalfKey/=1$keyTwo', - // 'keyFour/.0:$secondHalfKey/=1$keyFour', - // '/.0:$keyFive/=1$keyFiveInner', - // ]); - - // expect(mappedChildren[0]).toEqual(
); - // expect(mappedChildren[1]).toEqual(
); - // expect(mappedChildren[2]).toEqual(
); - // expect(mappedChildren[3]).toEqual(
); - // }); - - // it('should retain key across two mappings', function() { - // var zeroForceKey =
; - // var oneForceKey =
; - // - // // Key should be joined to object key - // var zeroForceKeyMapped =
; - // // Key should be added even if we don't supply it! - // var oneForceKeyMapped =
; - // - // var mapFn = function(kid, index) { - // return index === 0 ? zeroForceKeyMapped : oneForceKeyMapped; - // }; - // - // var forcedKeys = ( - //
- // {zeroForceKey} - // {oneForceKey} - //
- // ); - // - // var expectedForcedKeys = ['giraffe/.$keyZero', '/.$keyOne']; - // var mappedChildrenForcedKeys = - // ReactChildren.map(forcedKeys.props.children, mapFn); - // var mappedForcedKeys = mappedChildrenForcedKeys.map((c) => c.key); - // expect(mappedForcedKeys).toEqual(expectedForcedKeys); - // - // // var expectedRemappedForcedKeys = [ - // // 'giraffe/.$giraffe/=1$keyZero', - // // '/.$/=1$keyOne', - // // ]; - // // var remappedChildrenForcedKeys = - // // ReactChildren.map(mappedChildrenForcedKeys, mapFn); - // // expect( - // // remappedChildrenForcedKeys.map((c) => c.key) - // // ).toEqual(expectedRemappedForcedKeys); - // - // }); - it('should not throw if key provided is a dupe with array key', function () { const zero =
; const one =
; diff --git a/packages/inferno-compat/__tests__/ReactES6Class.spec.jsx b/packages/inferno-compat/__tests__/ReactES6Class.spec.jsx index fccff5a5b..60cfa8fac 100644 --- a/packages/inferno-compat/__tests__/ReactES6Class.spec.jsx +++ b/packages/inferno-compat/__tests__/ReactES6Class.spec.jsx @@ -148,21 +148,6 @@ describe('ReactES6Class', function () { expect(renderCount).toBe(1); }); - // it('should throw with non-object in the initial state property', function() { - // [['an array'], 'a string', 1234].forEach(function(state) { - // class Foo extends React.Component { - // constructor() { - // super(); - // this.state = state; - // } - // render() { - // return ; - // } - // } - // expect(() => test(, 'span', '')).toThrow(); - // }); - // }); - it('should render with null in the initial state property', function () { class Foo extends React.Component { constructor() { diff --git a/packages/inferno-compat/src/InfernoCompatPropertyMap.ts b/packages/inferno-compat/src/InfernoCompatPropertyMap.ts index fa56f0d20..96056a724 100644 --- a/packages/inferno-compat/src/InfernoCompatPropertyMap.ts +++ b/packages/inferno-compat/src/InfernoCompatPropertyMap.ts @@ -107,8 +107,8 @@ function capitalize(token: string): string { return token[1].toUpperCase(); } -ATTRS.forEach((original) => { +for (const original of ATTRS) { const reactName = original.replace(CAMELIZE, capitalize); InfernoCompatPropertyMap[reactName] = original; -}); +} diff --git a/packages/inferno-create-element/__tests__/children.spec.js b/packages/inferno-create-element/__tests__/children.spec.js index acc47042c..c2ca4b753 100644 --- a/packages/inferno-create-element/__tests__/children.spec.js +++ b/packages/inferno-create-element/__tests__/children.spec.js @@ -223,173 +223,143 @@ describe('Children - (non-JSX)', () => { }, ]; - preDefined.forEach((arg, i) => { - [ - { - description: 'should set static children as ' + arg.name, - template: () => createElement('div', null, arg.value), - }, - ].forEach((test) => { - it(test.description, () => { - render(test.template(), container); + for (const arg of preDefined) { + it('should set static children as ' + arg.name, () => { + render(createElement('div', null, arg.value), container); expect(container.firstChild.nodeType).toBe(1); expect(container.firstChild.textContent).toBe(arg.expected); - render(test.template(), container); + render(createElement('div', null, arg.value), container); expect(container.firstChild.nodeType).toBe(1); expect(container.firstChild.textContent).toBe(arg.expected); - }); }); - }); + } - preDefined.forEach((arg) => { - [ - { - description: 'should set static deep children as ' + arg.name, - template: () => - createElement('div', null, createElement('span', null, arg.value)), - }, - ].forEach((test) => { - it(test.description, () => { - render(test.template(), container); + for (const arg of preDefined) { + it('should set static deep children as ' + arg.name, () => { + const tmpl = () => createElement('div', null, createElement('span', null, arg.value)) + + render(tmpl(), container); expect(container.firstChild.nodeType).toBe(1); expect(container.firstChild.firstChild.nodeType).toBe(1); expect(container.firstChild.childNodes.length).toBe(1); expect(container.firstChild.firstChild.textContent).toBe(arg.expected); - render(test.template(), container); + render(tmpl(), container); expect(container.firstChild.nodeType).toBe(1); expect(container.firstChild.firstChild.nodeType).toBe(1); expect(container.firstChild.childNodes.length).toBe(1); expect(container.firstChild.firstChild.textContent).toBe(arg.expected); }); - }); - }); + } - preDefined.forEach((arg) => { - [ - { - description: 'should set very deep static children as ' + arg.name, - template: () => + for (const arg of preDefined) { + it('should set very deep static children as ' + arg.name, () => { + const tmpl = () => createElement( - 'div', - null, - createElement( - 'span', + 'div', null, - createElement('b', null, createElement('b', null, arg.value)), - ), - ), - }, - ].forEach((test) => { - it(test.description, () => { - render(test.template(), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.firstChild.firstChild.nodeType).toBe(1); - expect(container.firstChild.childNodes.length).toBe(1); - expect(container.firstChild.firstChild.textContent).toBe(arg.expected); - render(test.template(), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.firstChild.firstChild.nodeType).toBe(1); - expect(container.firstChild.childNodes.length).toBe(1); - expect(container.firstChild.firstChild.textContent).toBe(arg.expected); - }); + createElement( + 'span', + null, + createElement('b', null, createElement('b', null, arg.value)), + ), + ); + + render(tmpl(), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.firstChild.firstChild.nodeType).toBe(1); + expect(container.firstChild.childNodes.length).toBe(1); + expect(container.firstChild.firstChild.textContent).toBe(arg.expected); + render(tmpl(), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.firstChild.firstChild.nodeType).toBe(1); + expect(container.firstChild.childNodes.length).toBe(1); + expect(container.firstChild.firstChild.textContent).toBe(arg.expected); }); - }); + } - preDefined.forEach((arg) => { - [ - { - description: 'should set dynamic children as ' + arg.name, + for (const arg of preDefined) { + const template = (child) => createElement('div', null, child) - template: (child) => createElement('div', null, child), - }, - ].forEach((test) => { - it(test.description, () => { - render(test.template(arg.value), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.firstChild.textContent).toBe(arg.expected); - render(test.template(arg.value), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.firstChild.textContent).toBe(arg.expected); - render(test.template(), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.firstChild.textContent).toBe(''); - render(test.template(arg.value), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.firstChild.textContent).toBe(arg.expected); - }); + it('should set dynamic children as ' + arg.name, () => { + render(template(arg.value), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.firstChild.textContent).toBe(arg.expected); + render(template(arg.value), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.firstChild.textContent).toBe(arg.expected); + render(template(), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.firstChild.textContent).toBe(''); + render(template(arg.value), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.firstChild.textContent).toBe(arg.expected); + }); - it(test.description, () => { - render(test.template(), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.firstChild.textContent).toBe(''); - render(test.template(arg.value), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.firstChild.textContent).toBe(arg.expected); - }); + it('should set dynamic children as ' + arg.name, () => { + render(template(), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.firstChild.textContent).toBe(''); + render(template(arg.value), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.firstChild.textContent).toBe(arg.expected); + }); - it(test.description, () => { - render(test.template(null), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.firstChild.textContent).toBe(''); - render(test.template(arg.value), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.firstChild.textContent).toBe(arg.expected); - }); + it('should set dynamic children as ' + arg.name, () => { + render(template(null), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.firstChild.textContent).toBe(''); + render(template(arg.value), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.firstChild.textContent).toBe(arg.expected); + }); - it(test.description, () => { - render(test.template(arg.value), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.firstChild.textContent).toBe(arg.expected); - render(test.template(null), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.firstChild.textContent).toBe(''); - }); + it('should set dynamic children as ' + arg.name, () => { + render(template(arg.value), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.firstChild.textContent).toBe(arg.expected); + render(template(null), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.firstChild.textContent).toBe(''); + }); - it(test.description, () => { - render(test.template(), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.firstChild.textContent).toBe(''); - render(test.template(undefined), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.firstChild.textContent).toBe(''); - }); + it('should set dynamic children as ' + arg.name, () => { + render(template(), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.firstChild.textContent).toBe(''); + render(template(undefined), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.firstChild.textContent).toBe(''); + }); - it(test.description, () => { - render(test.template(null), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.firstChild.textContent).toBe(''); - render(test.template(null), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.firstChild.textContent).toBe(''); - }); + it('should set dynamic children as ' + arg.name, () => { + render(template(null), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.firstChild.textContent).toBe(''); + render(template(null), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.firstChild.textContent).toBe(''); }); - }); + } - preDefined.forEach((arg) => { - [ - { - description: 'should set deep dynamic children as ' + arg.name, - template: (child) => - createElement('div', null, createElement('b', null, child)), - }, - ].forEach((test) => { - it(test.description, () => { - render(test.template(arg.value), container); - expect(container.firstChild.firstChild.nodeType).toBe(1); - expect(container.firstChild.firstChild.textContent).toBe(arg.expected); - render(test.template(arg.value), container); - expect(container.firstChild.firstChild.nodeType).toBe(1); - expect(container.firstChild.firstChild.textContent).toBe(arg.expected); - render(test.template(null), container); - expect(container.firstChild.firstChild.nodeType).toBe(1); - expect(container.firstChild.firstChild.textContent).toBe(''); - render(test.template(undefined), container); - expect(container.firstChild.firstChild.nodeType).toBe(1); - expect(container.firstChild.firstChild.textContent).toBe(''); - render(test.template(), container); - expect(container.firstChild.firstChild.nodeType).toBe(1); - expect(container.firstChild.firstChild.textContent).toBe(''); - }); + for (const arg of preDefined) { + const template = (child) => createElement('div', null, createElement('b', null, child)); + + it('should set deep dynamic children as ' + arg.name, () => { + render(template(arg.value), container); + expect(container.firstChild.firstChild.nodeType).toBe(1); + expect(container.firstChild.firstChild.textContent).toBe(arg.expected); + render(template(arg.value), container); + expect(container.firstChild.firstChild.nodeType).toBe(1); + expect(container.firstChild.firstChild.textContent).toBe(arg.expected); + render(template(null), container); + expect(container.firstChild.firstChild.nodeType).toBe(1); + expect(container.firstChild.firstChild.textContent).toBe(''); + render(template(undefined), container); + expect(container.firstChild.firstChild.nodeType).toBe(1); + expect(container.firstChild.firstChild.textContent).toBe(''); + render(template(), container); + expect(container.firstChild.firstChild.nodeType).toBe(1); + expect(container.firstChild.firstChild.textContent).toBe(''); }); - }); + } }); diff --git a/packages/inferno-create-element/__tests__/components.spec.js b/packages/inferno-create-element/__tests__/components.spec.js index 00f856906..c120d6bda 100644 --- a/packages/inferno-create-element/__tests__/components.spec.js +++ b/packages/inferno-create-element/__tests__/components.spec.js @@ -1140,7 +1140,9 @@ describe('Components (non-JSX)', () => { render(tpl79713834(TEST), container); const buttons = container.querySelectorAll('button'); - buttons.forEach((button) => button.click()); + for (const button of buttons) { + button.click(); + } setTimeout(() => { expect(container.innerHTML).toBe( diff --git a/packages/inferno-create-element/__tests__/components.spec.jsx b/packages/inferno-create-element/__tests__/components.spec.jsx index 0f493c130..d75938531 100644 --- a/packages/inferno-create-element/__tests__/components.spec.jsx +++ b/packages/inferno-create-element/__tests__/components.spec.jsx @@ -502,7 +502,9 @@ describe('Components (JSX)', () => { it('Second render (update) #1', (done) => { render(, container); const buttons = container.querySelectorAll('button'); - buttons.forEach((button) => button.click()); + for (const button of buttons) { + button.click(); + } setTimeout(() => { expect(container.innerHTML).toBe( @@ -557,7 +559,9 @@ describe('Components (JSX)', () => { it('Second render (update with state change) #2', () => { render(, container); const buttons = container.querySelectorAll('button'); - buttons.forEach((button) => button.click()); + for (const button of buttons) { + button.click(); + } expect(container.innerHTML).toBe(''); }); @@ -611,7 +615,9 @@ describe('Components (JSX)', () => { it('Second render (update with state change) #3', (done) => { render(, container); const buttons = container.querySelectorAll('button'); - buttons.forEach((button) => button.click()); + for (const button of buttons) { + button.click(); + } setTimeout(() => { expect(container.innerHTML).toBe('

Kalle

'); @@ -880,7 +886,9 @@ describe('Components (JSX)', () => { render(, container); const buttons = container.querySelectorAll('button'); - buttons.forEach((button) => button.click()); + for (const button of buttons) { + button.click(); + } expect(container.innerHTML).toBe('
  • BMW
  • Volvo
  • Saab
'); }); @@ -925,7 +933,10 @@ describe('Components (JSX)', () => { render(, container); const buttons = container.querySelectorAll('button'); - buttons.forEach((button) => button.click()); + for (const button of buttons) { + button.click(); + } + setTimeout(() => { expect(container.innerHTML).toBe('
0
'); done(); @@ -982,7 +993,10 @@ describe('Components (JSX)', () => { render(, container); const buttons = container.querySelectorAll('button'); - buttons.forEach((button) => button.click()); + for (const button of buttons) { + button.click(); + } + setTimeout(() => { expect(container.innerHTML).toBe('

1-42

'); done(); @@ -1030,7 +1044,10 @@ describe('Components (JSX)', () => { render(, container); const buttons = container.querySelectorAll('button'); - buttons.forEach((button) => button.click()); + for (const button of buttons) { + button.click(); + } + setTimeout(() => { expect(container.innerHTML).toBe('

1

'); done(); @@ -1098,7 +1115,9 @@ describe('Components (JSX)', () => { render(, secondDiv); const buttons = firstDiv.querySelectorAll('button'); - buttons.forEach((button) => button.click()); + for (const button of buttons) { + button.click(); + } setTimeout(() => { expect(container.innerHTML).toBe('

1

0

'); @@ -1111,7 +1130,9 @@ describe('Components (JSX)', () => { render(, secondDiv); const buttons = secondDiv.querySelectorAll('button'); - buttons.forEach((button) => button.click()); + for (const button of buttons) { + button.click(); + } setTimeout(() => { expect(container.innerHTML).toBe('

0

1

'); @@ -1381,7 +1402,9 @@ describe('Components (JSX)', () => { expect(containerFlag).toBe(false); const spans = container.querySelectorAll('span'); - spans.forEach((span) => span.click()); + for (const span of spans) { + span.click(); + } expect(btnFlag).toBe(true); expect(containerFlag).toBe(true); @@ -1439,7 +1462,9 @@ describe('Components (JSX)', () => { expect(containerFlag).toBe(false); const spans = container.querySelectorAll('span'); - spans.forEach((span) => span.click()); + for (const span of spans) { + span.click(); + } expect(btnFlag).toBe(true); expect(containerFlag).toBe(false); diff --git a/packages/inferno-create-element/__tests__/createElement.spec.js b/packages/inferno-create-element/__tests__/createElement.spec.js index e186d076d..00ba2897f 100644 --- a/packages/inferno-create-element/__tests__/createElement.spec.js +++ b/packages/inferno-create-element/__tests__/createElement.spec.js @@ -44,7 +44,9 @@ describe('CreateElement (non-JSX)', () => { expect(triggered).toBe(false); const buttons = container.querySelectorAll('button'); - buttons.forEach((button) => button.click()); + for (const button of buttons) { + button.click(); + } expect(triggered).toBe(true); }); @@ -76,7 +78,9 @@ describe('CreateElement (non-JSX)', () => { expect(triggered).toBe(false); const buttons = container.querySelectorAll('button'); - buttons.forEach((button) => button.click()); + for (const button of buttons) { + button.click(); + } expect(triggered).toBe(true); }); diff --git a/packages/inferno-create-element/__tests__/creation.spec.js b/packages/inferno-create-element/__tests__/creation.spec.js index bc143917a..6f1c6e409 100644 --- a/packages/inferno-create-element/__tests__/creation.spec.js +++ b/packages/inferno-create-element/__tests__/creation.spec.js @@ -15,7 +15,7 @@ describe('Creation - (non-JSX)', () => { document.body.removeChild(container); }); - [ + const tests = [ { description: 'should render div with span child', template: () => { @@ -35,38 +35,38 @@ describe('Creation - (non-JSX)', () => { { description: 'should render div with two span children', template: () => - createElement('div', null, createElement('div'), createElement('div')), + createElement('div', null, createElement('div'), createElement('div')), tagName: 'div', children: 2, textContent: '', }, { description: - 'should render div with three span children and unset middle child', + 'should render div with three span children and unset middle child', template: () => - createElement( - 'div', - null, - createElement('span'), - null, - createElement('span'), - ), + createElement( + 'div', + null, + createElement('span'), + null, + createElement('span'), + ), tagName: 'div', children: 2, textContent: '', }, { description: - 'should render div with three span children and unset first, and middle child', + 'should render div with three span children and unset first, and middle child', template: () => - createElement('div', null, null, null, createElement('span')), + createElement('div', null, null, null, createElement('span')), tagName: 'div', children: 1, textContent: '', }, { description: - 'should render div with three span children and unset first, and middle child', + 'should render div with three span children and unset first, and middle child', template: () => createElement('div', null, null, null, null), tagName: 'div', children: 0, @@ -82,7 +82,7 @@ describe('Creation - (non-JSX)', () => { { description: 'should render div with one textNode and a span children', template: () => - createElement('div', null, 'Hello!', null, createElement('span')), + createElement('div', null, 'Hello!', null, createElement('span')), tagName: 'div', children: 2, textContent: 'Hello!', @@ -90,53 +90,53 @@ describe('Creation - (non-JSX)', () => { { description: 'should render div with two textNodes and a span children', template: () => - createElement( - 'div', - null, - 'Hello, ', - null, - 'World!', - createElement('span'), - ), + createElement( + 'div', + null, + 'Hello, ', + null, + 'World!', + createElement('span'), + ), tagName: 'div', children: 3, textContent: 'Hello, World!', }, { description: - 'should render div with two textNodes and a two span children', + 'should render div with two textNodes and a two span children', template: () => - createElement( - 'div', - null, - 'Hello, ', - createElement('span'), - 'World!', - createElement('span'), - ), + createElement( + 'div', + null, + 'Hello, ', + createElement('span'), + 'World!', + createElement('span'), + ), tagName: 'div', children: 4, textContent: 'Hello, World!', }, { description: - 'should render div with two textNodes and one span children, and span with textNode', + 'should render div with two textNodes and one span children, and span with textNode', template: () => - createElement( - 'div', - null, - 'Hello', - createElement('span'), - ', ', - createElement('span', null, 'World!'), - ), + createElement( + 'div', + null, + 'Hello', + createElement('span'), + ', ', + createElement('span', null, 'World!'), + ), tagName: 'div', children: 4, textContent: 'Hello, World!', }, { description: - 'should render div with tree null values in an array for children', + 'should render div with tree null values in an array for children', template: () => createElement('div', null, null, null, null), tagName: 'div', children: 0, @@ -144,18 +144,18 @@ describe('Creation - (non-JSX)', () => { }, { description: - 'should render div with b child, and tree null values in an array for children', + 'should render div with b child, and tree null values in an array for children', template: () => - createElement('div', null, createElement('b', null, null, null, null)), + createElement('div', null, createElement('b', null, null, null, null)), tagName: 'div', children: 1, textContent: '', }, { description: - 'should render div with b child, and number and two null values in an array for children', + 'should render div with b child, and number and two null values in an array for children', template: () => - createElement('div', null, createElement('b', null, null, 123, null)), + createElement('div', null, createElement('b', null, null, 123, null)), tagName: 'div', children: 1, textContent: '123', @@ -174,7 +174,9 @@ describe('Creation - (non-JSX)', () => { children: 0, textContent: '', }, - ].forEach((test) => { + ]; + + for (const test of tests) { it(test.description, () => { render(test.template(), container); expect(container.firstChild.nodeType).toBe(1); @@ -187,5 +189,5 @@ describe('Creation - (non-JSX)', () => { expect(container.firstChild.tagName.toLowerCase()).toBe(test.tagName); expect(container.firstChild.childNodes.length).toBe(test.children); }); - }); + } }); diff --git a/packages/inferno-create-element/__tests__/events.spec.js b/packages/inferno-create-element/__tests__/events.spec.js index cf499561b..1fccde638 100644 --- a/packages/inferno-create-element/__tests__/events.spec.js +++ b/packages/inferno-create-element/__tests__/events.spec.js @@ -38,7 +38,9 @@ describe('Basic event tests', () => { render(template(test), container); let divs = container.querySelectorAll('div'); - divs.forEach((div) => div.click()); + for (const div of divs) { + div.click(); + } expect(calledFirstTest).toBe(true); // reset @@ -46,7 +48,9 @@ describe('Basic event tests', () => { render(template(test2), container); divs = container.querySelectorAll('div'); - divs.forEach((div) => div.click()); + for (const div of divs) { + div.click(); + } expect(calledFirstTest).toBe(false); expect(calledSecondTest).toBe(true); @@ -57,7 +61,9 @@ describe('Basic event tests', () => { render(null, container); divs = container.querySelectorAll('div'); - divs.forEach((div) => div.click()); + for (const div of divs) { + div.click(); + } expect(calledFirstTest).toBe(false); expect(calledSecondTest).toBe(false); @@ -98,10 +104,14 @@ describe('Basic event tests', () => { expect(container.firstChild.innerHTML).toBe('Count 0'); expect(data.count).toBe(0); - buttons.forEach((button) => button.click()); + for (const button of buttons) { + button.click(); + } expect(container.firstChild.innerHTML).toBe('Count 1'); expect(data.count).toBe(1); - buttons.forEach((button) => button.click()); + for (const button of buttons) { + button.click(); + } expect(container.firstChild.innerHTML).toBe('Count 2'); expect(data.count).toBe(2); }); @@ -140,7 +150,9 @@ describe('Basic event tests', () => { expect(container.firstChild.innerHTML).toBe('Count 0'); expect(data.count).toBe(0); - buttons.forEach((button) => button.click()); + for (const button of buttons) { + button.click(); + } expect(container.firstChild.innerHTML).toBe('Count 0'); }); diff --git a/packages/inferno-create-element/__tests__/patchKeyedChildren.spec.js b/packages/inferno-create-element/__tests__/patchKeyedChildren.spec.js index b7476a459..1716b508e 100644 --- a/packages/inferno-create-element/__tests__/patchKeyedChildren.spec.js +++ b/packages/inferno-create-element/__tests__/patchKeyedChildren.spec.js @@ -1390,33 +1390,33 @@ describe('keyed-nodes', () => { } describe('Keyed algorithm', () => { - TESTS.forEach((t) => { + for (const t of TESTS) { const name = JSON.stringify(t[0]) + ' => ' + JSON.stringify(t[1]); - const testFn = () => { + + it(name, () => { checkInnerHtmlEquals( - gen(t[0], true), - gen(t[1], true), - gen(t[1], true), - true, + gen(t[0], true), + gen(t[1], true), + gen(t[1], true), + true, ); - }; - it(name, testFn); - }); + }); + } }); describe('Non keyed algorithm', () => { - TESTS.forEach((t) => { + for (const t of TESTS) { const name = JSON.stringify(t[0]) + ' => ' + JSON.stringify(t[1]); - const testFn = () => { + + it(name, () => { checkInnerHtmlEquals( - gen(t[0], false), - gen(t[1], false), - gen(t[1], false), - false, + gen(t[0], false), + gen(t[1], false), + gen(t[1], false), + false, ); - }; - it(name, testFn); - }); + }); + } }); }); }); diff --git a/packages/inferno-create-element/__tests__/text.spec.js b/packages/inferno-create-element/__tests__/text.spec.js index def3ef6b7..5aa39a3f7 100644 --- a/packages/inferno-create-element/__tests__/text.spec.js +++ b/packages/inferno-create-element/__tests__/text.spec.js @@ -4,11 +4,11 @@ import { createElement } from 'inferno-create-element'; describe('Text', () => { let container; - beforeEach(function () { + beforeEach(function() { container = document.createElement('div'); }); - afterEach(function () { + afterEach(function() { render(null, container); }); @@ -95,236 +95,172 @@ describe('Text', () => { }, ]; - emptyDefinitions.forEach((arg) => { - [ - { - description: 'should create a static text node with ' + arg.name, - template: () => createElement('div', null, arg.value), - }, - ].forEach((test) => { - it(test.description, () => { - render(test.template(), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.childNodes.length).toBe(1); - expect(container.firstChild.textContent).toBe(arg.expected); + for (const arg of emptyDefinitions) { + const template = () => createElement('div', null, arg.value) - render(test.template(), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.childNodes.length).toBe(1); - expect(container.firstChild.textContent).toBe(arg.expected); - }); + it('should create a static text node with ' + arg.name, () => { + render(template(), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.childNodes.length).toBe(1); + expect(container.firstChild.textContent).toBe(arg.expected); + + render(template(), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.childNodes.length).toBe(1); + expect(container.firstChild.textContent).toBe(arg.expected); }); - }); - emptyDefinitions.forEach((arg) => { - [ - { - description: 'should create a static text node with null', - template: () => createElement('div', null, null), - }, - ].forEach((test) => { - it(test.description, () => { - render(test.template(), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.childNodes.length).toBe(1); - expect(container.firstChild.textContent).toBe(''); + const template2 = () => createElement('div', null, null); - render(test.template(), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.childNodes.length).toBe(1); - expect(container.firstChild.textContent).toBe(''); - }); + it('should create a static text node with null', () => { + render(template2(), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.childNodes.length).toBe(1); + expect(container.firstChild.textContent).toBe(''); + + render(template2(), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.childNodes.length).toBe(1); + expect(container.firstChild.textContent).toBe(''); }); - }); - emptyDefinitions.forEach((arg) => { - [ - { - description: - 'should create a dynamic text node with ' + - arg.name + - ' - text property', - template: (text) => createElement('div', null, text), - }, - ].forEach((test) => { - it(test.description, () => { - render(test.template(arg.value), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.childNodes.length).toBe(1); - expect(container.firstChild.textContent).toBe(arg.expected); + const template3 = (text) => createElement('div', null, text); - render(test.template(arg.value), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.childNodes.length).toBe(1); - expect(container.firstChild.textContent).toBe(arg.expected); - }); + it(`should create a dynamic text node with ${arg.name} - text property 1`, () => { + render(template3(arg.value), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.childNodes.length).toBe(1); + expect(container.firstChild.textContent).toBe(arg.expected); - it(test.description, () => { - render(test.template(null), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.childNodes.length).toBe(1); - expect(container.firstChild.textContent).toBe(''); + render(template3(arg.value), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.childNodes.length).toBe(1); + expect(container.firstChild.textContent).toBe(arg.expected); + }); - render(test.template(arg.value), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.childNodes.length).toBe(1); - expect(container.firstChild.textContent).toBe(arg.expected); - }); + it(`should create a dynamic text node with ${arg.name} - text property 2`, () => { + render(template3(null), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.childNodes.length).toBe(1); + expect(container.firstChild.textContent).toBe(''); + + render(template3(arg.value), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.childNodes.length).toBe(1); + expect(container.firstChild.textContent).toBe(arg.expected); }); - }); - emptyDefinitions.forEach((arg) => { - [ - { - description: - 'should create a dynamic text node with ' + - arg.name + - ' - children node text', - template: (text) => - createElement('div', null, createElement('span', null, text)), - }, - ].forEach((test) => { - it(test.description, () => { - render(test.template(arg.value), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.childNodes.length).toBe(1); - expect(container.firstChild.childNodes.length).toBe(1); - expect(container.firstChild.firstChild.textContent).toBe(arg.expected); + const template4 = (text) => createElement('div', null, createElement('span', null, text)); - render(test.template(arg.value), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.childNodes.length).toBe(1); - expect(container.firstChild.childNodes.length).toBe(1); - expect(container.firstChild.firstChild.textContent).toBe(arg.expected); - }); + it('should create a dynamic text node with ' + arg.name + ' - children node text', () => { + render(template4(arg.value), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.childNodes.length).toBe(1); + expect(container.firstChild.childNodes.length).toBe(1); + expect(container.firstChild.firstChild.textContent).toBe(arg.expected); + + render(template4(arg.value), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.childNodes.length).toBe(1); + expect(container.firstChild.childNodes.length).toBe(1); + expect(container.firstChild.firstChild.textContent).toBe(arg.expected); }); - }); - emptyDefinitions.forEach((arg) => { - [ - { - description: - 'should create a dynamic text node with ' + - arg.name + - ' - single child with text ', - template: (text) => createElement('div', null, text), - }, - ].forEach((test) => { - it(test.description, () => { - render(test.template(arg.value), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.childNodes.length).toBe(1); - expect(container.firstChild.childNodes.length).toBe(1); - expect(container.firstChild.textContent).toBe(arg.expected); + const template5 = (text) => createElement('div', null, text); - render(test.template(arg.value), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.childNodes.length).toBe(1); - expect(container.firstChild.childNodes.length).toBe(1); - expect(container.firstChild.textContent).toBe(arg.expected); - }); + it('should create a dynamic text node with ' + arg.name + ' - single child with text ', () => { + render(template5(arg.value), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.childNodes.length).toBe(1); + expect(container.firstChild.childNodes.length).toBe(1); + expect(container.firstChild.textContent).toBe(arg.expected); + + render(template5(arg.value), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.childNodes.length).toBe(1); + expect(container.firstChild.childNodes.length).toBe(1); + expect(container.firstChild.textContent).toBe(arg.expected); }); - }); - emptyDefinitions.forEach((arg) => { - [ - { - description: - 'should create a dynamic text node with ' + - arg.name + - ' - deep child with text property ', - template: (text) => - createElement('div', null, createElement('span', null, text)), - }, - ].forEach((test) => { - it(test.description, () => { - render(test.template(arg.value), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.childNodes.length).toBe(1); - expect(container.firstChild.childNodes.length).toBe(1); - expect(container.firstChild.textContent).toBe(arg.expected); + const template6 = (text) => createElement('div', null, createElement('span', null, text)); - render(test.template(arg.value), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.childNodes.length).toBe(1); - expect(container.firstChild.childNodes.length).toBe(1); - expect(container.firstChild.textContent).toBe(arg.expected); - }); + it('should create a dynamic text node with ' + arg.name + ' - deep child with text property ', () => { + render(template6(arg.value), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.childNodes.length).toBe(1); + expect(container.firstChild.childNodes.length).toBe(1); + expect(container.firstChild.textContent).toBe(arg.expected); + + render(template6(arg.value), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.childNodes.length).toBe(1); + expect(container.firstChild.childNodes.length).toBe(1); + expect(container.firstChild.textContent).toBe(arg.expected); }); - }); - emptyDefinitions.forEach((arg) => { - [ - { - description: - 'should create a dynamic text node with ' + - arg.name + - ' - deeper child with text property ', - template: (text) => - createElement( + const template7 = (text) => + createElement( 'div', null, createElement('span', null, createElement('b', null, text)), - ), - }, - ].forEach((test) => { - it(test.description, () => { - render(test.template(arg.value), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.childNodes.length).toBe(1); - expect(container.firstChild.childNodes.length).toBe(1); - expect(container.firstChild.textContent).toBe(arg.expected); + ); - render(test.template(arg.value), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.childNodes.length).toBe(1); - expect(container.firstChild.childNodes.length).toBe(1); - expect(container.firstChild.textContent).toBe(arg.expected); - }); + it('should create a dynamic text node with ' + arg.name + ' - deeper child with text property', () => { + render(template7(arg.value), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.childNodes.length).toBe(1); + expect(container.firstChild.childNodes.length).toBe(1); + expect(container.firstChild.textContent).toBe(arg.expected); - it(test.description, () => { - render(test.template(null), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.childNodes.length).toBe(1); - expect(container.firstChild.childNodes.length).toBe(1); - expect(container.firstChild.textContent).toBe(''); + render(template7(arg.value), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.childNodes.length).toBe(1); + expect(container.firstChild.childNodes.length).toBe(1); + expect(container.firstChild.textContent).toBe(arg.expected); + }); - render(test.template(arg.value), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.childNodes.length).toBe(1); - expect(container.firstChild.childNodes.length).toBe(1); - expect(container.firstChild.textContent).toBe(arg.expected); - }); + it('should create a dynamic text node with ' + arg.name + ' - deeper child with text property', () => { + render(template7(null), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.childNodes.length).toBe(1); + expect(container.firstChild.childNodes.length).toBe(1); + expect(container.firstChild.textContent).toBe(''); - it(test.description, () => { - render(test.template(arg.value), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.childNodes.length).toBe(1); - expect(container.firstChild.childNodes.length).toBe(1); - expect(container.firstChild.textContent).toBe(arg.expected); + render(template7(arg.value), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.childNodes.length).toBe(1); + expect(container.firstChild.childNodes.length).toBe(1); + expect(container.firstChild.textContent).toBe(arg.expected); + }); - render(test.template(null), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.childNodes.length).toBe(1); - expect(container.firstChild.childNodes.length).toBe(1); - expect(container.firstChild.textContent).toBe(''); - }); + it('should create a dynamic text node with ' + arg.name + ' - deeper child with text property', () => { + render(template7(arg.value), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.childNodes.length).toBe(1); + expect(container.firstChild.childNodes.length).toBe(1); + expect(container.firstChild.textContent).toBe(arg.expected); - it(test.description, () => { - render(test.template(null), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.childNodes.length).toBe(1); - expect(container.firstChild.childNodes.length).toBe(1); - expect(container.firstChild.textContent).toBe(''); + render(template7(null), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.childNodes.length).toBe(1); + expect(container.firstChild.childNodes.length).toBe(1); + expect(container.firstChild.textContent).toBe(''); + }); - render(test.template(null), container); - expect(container.firstChild.nodeType).toBe(1); - expect(container.childNodes.length).toBe(1); - expect(container.firstChild.childNodes.length).toBe(1); - expect(container.firstChild.textContent).toBe(''); - }); + it('should create a dynamic text node with ' + arg.name + ' - deeper child with text property', () => { + render(template7(null), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.childNodes.length).toBe(1); + expect(container.firstChild.childNodes.length).toBe(1); + expect(container.firstChild.textContent).toBe(''); + + render(template7(null), container); + expect(container.firstChild.nodeType).toBe(1); + expect(container.childNodes.length).toBe(1); + expect(container.firstChild.childNodes.length).toBe(1); + expect(container.firstChild.textContent).toBe(''); }); - }); + } const multiArray = [ { @@ -419,26 +355,21 @@ describe('Text', () => { }, ]; - multiArray.forEach((arg) => { - [ - { - description: 'should create a children property with ' + arg.name, - template: (textVar) => createElement('div', null, textVar), - }, - ].forEach((test) => { - it(test.description, () => { - render(test.template(arg.value), container); + for (const arg of multiArray) { + const template1 = (textVar) => createElement('div', null, textVar); + + it('should create a children property with ' + arg.name, () => { + render(template1(arg.value), container); expect(container.firstChild.nodeType).toBe(1); expect(container.childNodes.length).toBe(1); expect(container.firstChild.childNodes.length).toBe(arg.children); expect(container.firstChild.textContent).toBe(arg.expected); - render(test.template(arg.value), container); + render(template1(arg.value), container); expect(container.firstChild.nodeType).toBe(1); expect(container.childNodes.length).toBe(1); expect(container.firstChild.childNodes.length).toBe(arg.children); expect(container.firstChild.textContent).toBe(arg.expected); }); - }); - }); + } }); diff --git a/packages/inferno-hyperscript/__tests__/hyperscript.spec.jsx b/packages/inferno-hyperscript/__tests__/hyperscript.spec.jsx index c6718db95..045e5fdb4 100644 --- a/packages/inferno-hyperscript/__tests__/hyperscript.spec.jsx +++ b/packages/inferno-hyperscript/__tests__/hyperscript.spec.jsx @@ -239,7 +239,9 @@ describe('HyperScript (non-JSX)', () => { expect(triggered).toBe(false); const buttons = container.querySelectorAll('button'); - buttons.forEach((button) => button.click()); + for (const button of buttons) { + button.click(); + } expect(triggered).toBe(true); }); @@ -271,7 +273,9 @@ describe('HyperScript (non-JSX)', () => { expect(triggered).toBe(false); const buttons = container.querySelectorAll('button'); - buttons.forEach((button) => button.click()); + for (const button of buttons) { + button.click(); + } expect(triggered).toBe(true); }); diff --git a/packages/inferno-mobx/__tests__/inject.spec.jsx b/packages/inferno-mobx/__tests__/inject.spec.jsx index 6083f2fe4..7853cffa1 100644 --- a/packages/inferno-mobx/__tests__/inject.spec.jsx +++ b/packages/inferno-mobx/__tests__/inject.spec.jsx @@ -357,99 +357,4 @@ describe('inject based context', () => { expect(container.querySelector('h1').textContent).toBe('Veria'); done(); }); - - // it('using a custom injector is not too reactive', done => { - // let listRender = 0; - // let itemRender = 0; - // let injectRender = 0; - // - // function connect() { - // return (component) => inject.apply(this, arguments)(observer(component)) - // } - // - // class State { - // @observable highlighted = null; - // isHighlighted(item) { - // return this.highlighted == item; - // } - // - // @action.bound highlight(item) { - // this.highlighted = item; - // } - // } - // - // const items = observable([ - // { title: 'ItemA' }, - // { title: 'ItemB' }, - // { title: 'ItemC' }, - // { title: 'ItemD' }, - // { title: 'ItemE' }, - // { title: 'ItemF' }, - // ]); - // - // const state = new State(); - // - // class ListComponent extends Component { - // - // render() { - // listRender++; - // const {items} = this.props; - // - // return
    { - // items.map((item) => ) - // }
- // } - // } - // - // @connect(({state}, {item}) => { - // injectRender++; - // if (injectRender > 6) { - // } - // return ({ - // // Using - // // highlighted: expr(() => state.isHighlighted(item)) // seems to fix the problem - // highlighted: state.isHighlighted(item), - // highlight: state.highlight - // }) - // }) - // class ItemComponent extends Component { - // highlight = () => { - // const {item, highlight} = this.props; - // highlight(item); - // }; - // - // render() { - // itemRender++; - // const {highlighted, item} = this.props; - // return
  • { item.title } { highlighted ? '(highlighted)' : '' }
  • - // } - // } - // - // render( - // - // - // , - // container - // ); - // - // expect(listRender).toBe(1); - // expect(injectRender).toBe(6); - // expect(itemRender).toBe(6); - // - // - // container.querySelectorAll(".hl_ItemB").forEach(e => e.click()); - // setTimeout(() => { - // expect(listRender).toBe(1); - // expect(injectRender).toBe(12); // ideally, 7 - // expect(itemRender).toBe(7); - // - // container.querySelectorAll(".hl_ItemF").forEach(e => e.click()); - // setTimeout(() => { - // expect(listRender).toBe(1); - // expect(injectRender).toBe(18); // ideally, 9 - // expect(itemRender).toBe(9); - // done(); - // }, 20); - // }, 20); - // }); }); diff --git a/packages/inferno-redux/__tests__/components/connect.spec.js b/packages/inferno-redux/__tests__/components/connect.spec.js index 34107bcee..a83e37d9c 100644 --- a/packages/inferno-redux/__tests__/components/connect.spec.js +++ b/packages/inferno-redux/__tests__/components/connect.spec.js @@ -79,7 +79,9 @@ describe('Inferno', () => { dispatch(action) { this.state = this.reducer(this.state, action); - this.listeners.forEach((l) => l()); + for (const l of this.listeners) { + l(); + } return action; } } @@ -1533,13 +1535,13 @@ describe('Inferno', () => { const imitateHotReloading = (TargetClass, SourceClass) => { // Crude imitation of hot reloading that does the job - Object.getOwnPropertyNames(SourceClass.prototype) - .filter((key) => typeof SourceClass.prototype[key] === 'function') - .forEach((key) => { - if (key !== 'render' && key !== 'constructor') { - TargetClass.prototype[key] = SourceClass.prototype[key]; - } - }); + const fns = Object.getOwnPropertyNames(SourceClass.prototype).filter((key) => typeof SourceClass.prototype[key] === 'function'); + + for (const key of fns) { + if (key !== 'render' && key !== 'constructor') { + TargetClass.prototype[key] = SourceClass.prototype[key]; + } + } container.forceUpdate(); }; diff --git a/packages/inferno-router/__tests__/mobx-router.spec.tsx b/packages/inferno-router/__tests__/mobx-router.spec.tsx index ece2fbf27..296c3d078 100644 --- a/packages/inferno-router/__tests__/mobx-router.spec.tsx +++ b/packages/inferno-router/__tests__/mobx-router.spec.tsx @@ -65,9 +65,9 @@ describe('Github #1236', () => { context?, ) { let desc: any = {}; - Object['ke' + 'ys'](descriptor).forEach(function (key) { + for (const key of Object['ke' + 'ys'](descriptor)) { desc[key] = descriptor[key]; - }); + } desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; diff --git a/packages/inferno-server/__tests__/creation-stream.spec.server.jsx b/packages/inferno-server/__tests__/creation-stream.spec.server.jsx index d08ff6be3..65a5345bf 100644 --- a/packages/inferno-server/__tests__/creation-stream.spec.server.jsx +++ b/packages/inferno-server/__tests__/creation-stream.spec.server.jsx @@ -328,7 +328,7 @@ describe('SSR Creation Streams - (non-JSX)', () => { } ]; - testEntries.forEach((test) => { + for (const test of testEntries) { it(test.description, () => { const container = document.createElement('div'); const vDom = test.template('foo'); @@ -336,7 +336,7 @@ describe('SSR Creation Streams - (non-JSX)', () => { expect(output).toBe(test.result); }); }); - }); + } describe('Component hook', () => { it('Should allow changing state in CWM', () => { diff --git a/packages/inferno-server/__tests__/creation.spec.server.jsx b/packages/inferno-server/__tests__/creation.spec.server.jsx index 23477c7ef..39aca42ae 100644 --- a/packages/inferno-server/__tests__/creation.spec.server.jsx +++ b/packages/inferno-server/__tests__/creation.spec.server.jsx @@ -190,14 +190,14 @@ describe('SSR Creation (JSX)', () => { } ]; - testEntries.forEach((test) => { + for (const test of testEntries) { it(test.description, () => { const vDom = test.template('foo'); const output = renderToStaticMarkup(vDom); expect(output).toBe(test.result); }); - }); + } describe('Component hook', () => { it('Should allow changing state in CWM', () => { diff --git a/packages/inferno-server/__tests__/hydration-ext.spec.server.jsx b/packages/inferno-server/__tests__/hydration-ext.spec.server.jsx index 204ea7c62..5c17d6fe5 100644 --- a/packages/inferno-server/__tests__/hydration-ext.spec.server.jsx +++ b/packages/inferno-server/__tests__/hydration-ext.spec.server.jsx @@ -42,7 +42,7 @@ const compHtml2 = '
    C 1
    C 2
    C 3
    '; describe('SSR Hydration Extended - (JSX)', () => { - [ + const tests = [ { html: '
    Hello world
    ', component: , @@ -70,21 +70,59 @@ describe('SSR Hydration Extended - (JSX)', () => { { html: '
    ', component: ( - - - - - + + + + + ), }, - ].forEach(({ html, component }, i) => { + ]; + + for (let i = 0; i < tests.length; i++){ + const { html, component } = [ + { + html: '
    Hello world
    ', + component: , + }, + { + html: '
    Hello world
    Hello world
    Hello world
    Hello world
    Hello world
    ', + component: , + }, + { + html: '
    Hello world
    ', + component: , + }, + { + html: '
    Hello world
    Hola
    ', + component: , + }, + { + html: '
    Hello world
    block 1
    block 2
    block 3
    ', + component: , + }, + { + html: '
    Hello world
    block 1
    block 2
    block 3
    Hola
    ', + component: , + }, + { + html: '
    ', + component: ( + + + + + + ), + }, + ][i]; it(`do test #${i + 1}`, () => { const container = createContainerWithHTML(html); hydrate(component, container); expect(container.innerHTML).toEqual(compHtml); }); - }); + } it('Should hydrate correctly when CSR children is missing', () => { const container = createContainerWithHTML('
    '); diff --git a/packages/inferno-server/__tests__/hydration.spec.server.js b/packages/inferno-server/__tests__/hydration.spec.server.js index f1615623e..0c5f56e08 100644 --- a/packages/inferno-server/__tests__/hydration.spec.server.js +++ b/packages/inferno-server/__tests__/hydration.spec.server.js @@ -5,27 +5,23 @@ import { createElement } from 'inferno-create-element'; import { createContainerWithHTML, validateNodeTree } from 'inferno-utils'; describe('SSR Hydration - (non-JSX)', () => { - [ - { - node: createElement( - 'div', - null, - createElement('span', null, 'Hello world'), - ), - expect1: '
    Hello world
    ', - expect2: '
    Hello world
    ', - }, - ].forEach(({ node, expect1, expect2 }, i) => { - it(`Validate various structures #${i + 1}`, () => { - const html = renderToString(node); - const container = createContainerWithHTML(html); + const node = createElement( + 'div', + null, + createElement('span', null, 'Hello world'), + ); + const expect1 = '
    Hello world
    '; + const expect2 = '
    Hello world
    '; - expect(container.innerHTML).toBe(expect1); - hydrate(node, container); - expect(validateNodeTree(node)).toBe(true); - expect(container.innerHTML).toBe(expect2); - render(node, container); - expect(container.innerHTML).toBe(expect2); - }); + it('Validate various structures', () => { + const html = renderToString(node); + const container = createContainerWithHTML(html); + + expect(container.innerHTML).toBe(expect1); + hydrate(node, container); + expect(validateNodeTree(node)).toBe(true); + expect(container.innerHTML).toBe(expect2); + render(node, container); + expect(container.innerHTML).toBe(expect2); }); }); diff --git a/packages/inferno-server/__tests__/security.spec.server.jsx b/packages/inferno-server/__tests__/security.spec.server.jsx index ae66875ad..542cafe5f 100644 --- a/packages/inferno-server/__tests__/security.spec.server.jsx +++ b/packages/inferno-server/__tests__/security.spec.server.jsx @@ -48,7 +48,7 @@ describe('Security - SSR', () => { }); describe('streams', () => { - [streamAsString, streamQueueAsString].forEach((method) => { + for (const method of [streamAsString, streamQueueAsString]) { it('Should not render invalid attribute names', () => { const props = {}; const userProvidedData = '>
    '; @@ -83,7 +83,7 @@ describe('Security - SSR', () => { done(); }); }); - }); + } }); }); diff --git a/packages/inferno-server/__tests__/ssr-forwardref.spec.tsx b/packages/inferno-server/__tests__/ssr-forwardref.spec.tsx index e04eb2519..ced8736fb 100644 --- a/packages/inferno-server/__tests__/ssr-forwardref.spec.tsx +++ b/packages/inferno-server/__tests__/ssr-forwardref.spec.tsx @@ -42,158 +42,156 @@ describe('SSR -> Hydrate - Forward Ref', () => { } } - [renderToString, streamAsString, streamQueueAsString].forEach( - function (method) { - it('Should be possible to forward createRef', (done) => { - const FancyButton = forwardRef((props, ref) => ( - - )); + for (const method of [renderToString, streamAsString, streamQueueAsString]) { + it('Should be possible to forward createRef', (done) => { + const FancyButton = forwardRef((props, ref) => ( + + )); - expect(FancyButton.render).toBeDefined(); + expect(FancyButton.render).toBeDefined(); - class Hello extends Component { - private readonly btn: RefObject; + class Hello extends Component { + private readonly btn: RefObject; - constructor(props) { - super(props); + constructor(props) { + super(props); - // You can now get a ref directly to the DOM button: - this.btn = createRef(); - } - - public componentDidMount() { - expect(this.btn.current).toBe(container.querySelector('button')); - } - - public render() { - return Click me!; - } + // You can now get a ref directly to the DOM button: + this.btn = createRef(); } - SSRtoString(method, , function (htmlString) { - expect(htmlString).toBe( - '', - ); - - container.innerHTML = htmlString; - - renderToString(); - - expect(container.innerHTML).toBe( - '', - ); - - hydrate(, container); - - expect(container.innerHTML).toBe( - '', - ); - - done(); - }); - }); + public componentDidMount() { + expect(this.btn.current).toBe(container.querySelector('button')); + } - it('Should be possible to forward callback ref', (done) => { - const FancyButton = forwardRef((props, ref) => ( - - )); - - expect(FancyButton.render).toBeDefined(); - - class Hello extends Component { - public render() { - return ( - { - if (btn) { - expect(btn).toBe(container.querySelector('button')); - } - }} - > - Click me! - - ); - } + public render() { + return Click me!; } + } - SSRtoString(method, , function (htmlString) { - container.innerHTML = htmlString; + SSRtoString(method, , function (htmlString) { + expect(htmlString).toBe( + '', + ); - expect(container.innerHTML).toBe( - '', - ); + container.innerHTML = htmlString; - hydrate(, container); + renderToString(); - expect(container.innerHTML).toBe( - '', - ); + expect(container.innerHTML).toBe( + '', + ); - render(null, container); + hydrate(, container); - expect(container.innerHTML).toBe(''); + expect(container.innerHTML).toBe( + '', + ); - done(); - }); + done(); }); + }); - it('Should be possible to patch forwardRef component', () => { - const FancyButton = forwardRef((props, ref) => { - return ( - - ); - }); - - expect(FancyButton.render).toBeDefined(); - - SSRtoString(method, , function (htmlString) { - let firstVal: Element | null = null; + it('Should be possible to forward callback ref', (done) => { + const FancyButton = forwardRef((props, ref) => ( + + )); - container.innerHTML = htmlString; + expect(FancyButton.render).toBeDefined(); - hydrate( + class Hello extends Component { + public render() { + return ( { - firstVal = btn; + if (btn) { + expect(btn).toBe(container.querySelector('button')); + } }} > Click me! - , - container, + ); + } + } - expect(container.innerHTML).toBe( - '', - ); - expect(firstVal).not.toBe(null); + SSRtoString(method, , function (htmlString) { + container.innerHTML = htmlString; - let secondVal: Element | null = null; + expect(container.innerHTML).toBe( + '', + ); - render( - { - secondVal = btn; - }} - > - Click me! 222 - , - container, - ); + hydrate(, container); - expect(firstVal).toBe(null); - expect(secondVal).not.toBe(null); + expect(container.innerHTML).toBe( + '', + ); - expect(container.innerHTML).toBe( - '', - ); - }); + render(null, container); + + expect(container.innerHTML).toBe(''); + + done(); }); - }, - ); + }); + + it('Should be possible to patch forwardRef component', () => { + const FancyButton = forwardRef((props, ref) => { + return ( + + ); + }); + + expect(FancyButton.render).toBeDefined(); + + SSRtoString(method, , function (htmlString) { + let firstVal: Element | null = null; + + container.innerHTML = htmlString; + + hydrate( + { + firstVal = btn; + }} + > + Click me! + , + container, + ); + + expect(container.innerHTML).toBe( + '', + ); + expect(firstVal).not.toBe(null); + + let secondVal: Element | null = null; + + render( + { + secondVal = btn; + }} + > + Click me! 222 + , + container, + ); + + expect(firstVal).toBe(null); + expect(secondVal).not.toBe(null); + + expect(container.innerHTML).toBe( + '', + ); + }); + }); + } }); diff --git a/packages/inferno-test-utils/__tests__/testUtils.spec.jsx b/packages/inferno-test-utils/__tests__/testUtils.spec.jsx index 18d685933..7dd4de691 100644 --- a/packages/inferno-test-utils/__tests__/testUtils.spec.jsx +++ b/packages/inferno-test-utils/__tests__/testUtils.spec.jsx @@ -565,9 +565,9 @@ describe('Test Utils', () => { const result1 = scryRenderedDOMElementsWithClass(tree3, 'one'); expect(result1 instanceof Array).toBeTruthy(); expect(result1.length).toBe(3); - result1.forEach((result) => { + for (const result of result1) { expect(result.tagName).toBe('DIV'); - }); + } const result2 = scryRenderedDOMElementsWithClass(tree3, 'two'); expect(result2 instanceof Array).toBeTruthy(); @@ -620,9 +620,9 @@ describe('Test Utils', () => { const result = scryRenderedDOMElementsWithTag(tree4, tagName); expect(result instanceof Array).toBeTruthy(); expect(result.length).toBe(length); - result.forEach((item) => { + for (const item of result) { expect(item.tagName).toBe(tagName.toUpperCase()); - }); + } }; testValue('div', 1); testValue('h1', 2); @@ -648,11 +648,11 @@ describe('Test Utils', () => { const result = scryRenderedVNodesWithType(tree5, type); expect(result instanceof Array).toBeTruthy(); expect(result.length).toBe(length); - result.forEach((item) => { + for (const item of result) { expect(item instanceof Object).toBeTruthy(); expect(Object.keys(item).sort()).toEqual(VNodeKeys); expect(isVNode(item)).toBe(true); - }); + } }; testValue('p', 0); testValue('div', 7); // Outer div + each rendered component div @@ -680,11 +680,11 @@ describe('Test Utils', () => { const result = scryVNodesWithType(tree6, type); expect(result instanceof Array).toBeTruthy(); expect(result.length).toBe(length); - result.forEach((item) => { + for (const item of result) { expect(item instanceof Object).toBeTruthy(); expect(Object.keys(item).sort()).toEqual(VNodeKeys); expect(isVNode(item)).toBe(true); - }); + } }; testValue('p', 0); testValue('div', 1); // Just the outer div diff --git a/packages/inferno-test-utils/src/index.ts b/packages/inferno-test-utils/src/index.ts index 39492188c..7f4ad81c0 100644 --- a/packages/inferno-test-utils/src/index.ts +++ b/packages/inferno-test-utils/src/index.ts @@ -124,13 +124,13 @@ export function findAllInVNodeTree( findAllInVNodeTree(children, predicate) as VNode[], ); } else if (isArray(children)) { - children.forEach((child) => { + for (const child of children) { if (!isInvalid(child)) { result = result.concat( findAllInVNodeTree(child, predicate) as VNode[], ); } - }); + } } return result; } else { diff --git a/packages/inferno/__tests__/blueprints.spec.tsx b/packages/inferno/__tests__/blueprints.spec.tsx index a59da095f..736891eb1 100644 --- a/packages/inferno/__tests__/blueprints.spec.tsx +++ b/packages/inferno/__tests__/blueprints.spec.tsx @@ -95,7 +95,9 @@ describe('Blueprints (JSX)', () => { it('Second render (update)', () => { render(, container); const buttons = container.querySelectorAll('button'); - buttons.forEach((button) => button.click()); + for (const button of buttons) { + button.click(); + } expect(container.innerHTML).toBe( '

    Saab
    A

    Volvo
    A

    BMW
    A

    ', diff --git a/packages/inferno/__tests__/columnrender.spec.tsx b/packages/inferno/__tests__/columnrender.spec.tsx index 0416e1900..26db3bfde 100644 --- a/packages/inferno/__tests__/columnrender.spec.tsx +++ b/packages/inferno/__tests__/columnrender.spec.tsx @@ -253,7 +253,7 @@ describe('Columns like tests - (JSX)', () => { updateItemSpy.calls.reset(); }); - keyedTests.forEach((testCase) => { + for (const testCase of keyedTests) { it('Should ' + testCase.name, () => { const columnsToBeAdded = getDifferentObjects( testCase.update, @@ -336,7 +336,7 @@ describe('Columns like tests - (JSX)', () => { expect(updateItemSpy.calls.count()).toBe(itemsToUpdate.length); // Initial render none to update expect(unmountItemSpy.calls.count()).toBe(itemsToRemove.length); // Initial render none unmounted }); - }); + } }); describe('columns NON-KEYED', () => { @@ -438,7 +438,7 @@ describe('Columns like tests - (JSX)', () => { updateItemSpy.calls.reset(); }); - nonKeyedTestCases.forEach((testCase) => { + for (const testCase of nonKeyedTestCases) { it('Should ' + testCase.name, () => { const columnsToBeAdded = getDifferentObjects( testCase.update, @@ -521,7 +521,7 @@ describe('Columns like tests - (JSX)', () => { expect(updateItemSpy.calls.count()).toBe(itemsToUpdate.length); // Initial render none to update expect(unmountItemSpy.calls.count()).toBe(itemsToRemove.length); // Initial render none unmounted }); - }); + } }); }); }); diff --git a/packages/inferno/__tests__/error.spec.tsx b/packages/inferno/__tests__/error.spec.tsx index 7cf0b2313..2bcff6dac 100644 --- a/packages/inferno/__tests__/error.spec.tsx +++ b/packages/inferno/__tests__/error.spec.tsx @@ -124,8 +124,8 @@ describe('Error recovery', () => { */ describe('Error recovery from user land errors', () => { - ['last', 'mid', 'first'].forEach((location) => { - [ + for (const location of ['last', 'mid', 'first']) { + for (const crashLocation of [ 'render', 'constructor', 'DidMount', @@ -135,7 +135,7 @@ describe('Error recovery', () => { 'WillUpdate', 'DidUpdate', 'getChildContext', - ].forEach((crashLocation) => { + ]) { it( 'Should recover from subtree crash in ' + location + @@ -278,11 +278,11 @@ describe('Error recovery', () => { ); }, ); - }); - }); + } + } - ['last', 'mid', 'first'].forEach((location) => { - [ + for (const location of ['last', 'mid', 'first']) { + for (const crashLocation of [ 'render', 'constructor', 'DidMount', @@ -292,7 +292,7 @@ describe('Error recovery', () => { 'WillUpdate', 'DidUpdate', 'getChildContext', - ].forEach((crashLocation) => { + ]) { it( 'Should recover from subtree crash in NON-KEYED ' + location + @@ -435,11 +435,11 @@ describe('Error recovery', () => { ); }, ); - }); - }); + } + } - ['last', 'mid', 'first'].forEach((location) => { - [ + for (const location of ['last', 'mid', 'first']) { + for (const crashLocation of [ 'render', 'constructor', 'DidMount', @@ -449,7 +449,7 @@ describe('Error recovery', () => { 'WillUpdate', 'DidUpdate', 'getChildContext', - ].forEach((crashLocation) => { + ]) { it( 'Should recover from subtree crash in NON-KEYED ' + location + @@ -592,8 +592,8 @@ describe('Error recovery', () => { ); }, ); - }); - }); + } + } describe('Error in child component', () => { it('Should not block future updates', (done) => { diff --git a/packages/inferno/__tests__/portal.spec.tsx b/packages/inferno/__tests__/portal.spec.tsx index 62d9ad3ab..6746c3abd 100644 --- a/packages/inferno/__tests__/portal.spec.tsx +++ b/packages/inferno/__tests__/portal.spec.tsx @@ -44,12 +44,12 @@ describe('Portal spec', () => { mathEls = []; render(tree, container); - svgEls.forEach((el) => { + for (const el of svgEls) { expect(el.namespaceURI).toBe('http://www.w3.org/2000/svg'); - }); - htmlEls.forEach((el) => { + } + for (const el of htmlEls) { expect(el.namespaceURI).toBe('http://www.w3.org/1999/xhtml'); - }); + } render(null, container); expect(container.innerHTML).toBe('');