From f8cdcfe129cfb4c4bc46ce68feb9e880f2d8be98 Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz <thiemo.kreuz@wikimedia.de> Date: Tue, 7 Sep 2021 14:26:34 +0200 Subject: [PATCH] Consistent use of .forEach() in QUnit tests * The extra brackets are not needed in ES6. * Make sure the name of the test is on the next line. This makes the code easier to read. Change-Id: Ib871dbfa27fcadc88e7335b9efb4d583bd4300ac --- .../models/ve.dm.MWTemplateSpecModel.test.js | 12 +++---- .../tests/dm/ve.dm.MWTemplateModel.test.js | 31 ++++++++++--------- ....ui.MWParameterCheckboxInputWidget.test.js | 28 ++++++++++------- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/modules/ve-mw/tests/dm/models/ve.dm.MWTemplateSpecModel.test.js b/modules/ve-mw/tests/dm/models/ve.dm.MWTemplateSpecModel.test.js index 0e37396fd5..7447ef48ea 100644 --- a/modules/ve-mw/tests/dm/models/ve.dm.MWTemplateSpecModel.test.js +++ b/modules/ve-mw/tests/dm/models/ve.dm.MWTemplateSpecModel.test.js @@ -115,7 +115,7 @@ null, [], {} - ].forEach( ( templateData ) => { + ].forEach( ( templateData ) => QUnit.test( 'Invalid TemplateData, e.g. empty or without params', ( assert ) => { const template = createTemplateMock(), spec = new ve.dm.MWTemplateSpecModel( template ); @@ -136,8 +136,8 @@ assert.strictEqual( spec.isParameterSuggested( 'p' ), false, 'isParameterSuggested' ); assert.strictEqual( spec.isParameterDeprecated( 'p' ), false, 'isParameterDeprecated' ); assert.strictEqual( spec.getParameterDeprecationDescription( 'p' ), '', 'getParameterDeprecationDescription' ); - } ); - } ); + } ) + ); QUnit.test( 'Basic behavior with minimal setTemplateData()', ( assert ) => { const template = createTemplateMock( [ 'p1' ] ), @@ -283,7 +283,7 @@ [ { notemplatedata: false }, true, 'unexpected false' ], [ { notemplatedata: '' }, true, 'unsupported formatversion=1' ] - ].forEach( ( [ templateData, expected, message ] ) => { + ].forEach( ( [ templateData, expected, message ] ) => QUnit.test( 'isDocumented(): ' + message, ( assert ) => { const template = createTemplateMock(), spec = new ve.dm.MWTemplateSpecModel( template ); @@ -292,8 +292,8 @@ spec.setTemplateData( templateData ); assert.strictEqual( spec.isDocumented(), expected ); - } ); - } ); + } ) + ); QUnit.test( 'getDocumentedParameterOrder() should not return a reference', ( assert ) => { const template = createTemplateMock(), diff --git a/modules/ve-mw/tests/dm/ve.dm.MWTemplateModel.test.js b/modules/ve-mw/tests/dm/ve.dm.MWTemplateModel.test.js index a79ec9e2ab..a15d11923a 100644 --- a/modules/ve-mw/tests/dm/ve.dm.MWTemplateModel.test.js +++ b/modules/ve-mw/tests/dm/ve.dm.MWTemplateModel.test.js @@ -43,11 +43,13 @@ [ '/unexpected_prefix', '/unexpected prefix' ], [ './Template:%C3%9Cnicode%5Fexample/subpage', 'Template:Ünicode example/subpage' ], [ './Template:Possibly_invalid%5B%5D', 'Template:Possibly invalid[]' ] - ].forEach( ( [ href, expected ] ) => QUnit.test( 'getTitle: ' + href, ( assert ) => { - const transclusion = { getUniquePartId: () => 0 }, - template = new ve.dm.MWTemplateModel( transclusion, { href } ); - assert.strictEqual( template.getTitle(), expected ); - } ) ); + ].forEach( ( [ href, expected ] ) => + QUnit.test( 'getTitle: ' + href, ( assert ) => { + const transclusion = { getUniquePartId: () => 0 }, + template = new ve.dm.MWTemplateModel( transclusion, { href } ); + assert.strictEqual( template.getTitle(), expected ); + } ) + ); QUnit.test( 'hasParameter', ( assert ) => { const template = newTemplateModel(); @@ -164,7 +166,7 @@ }, expected: [ 'foo', 'bar', 'empty' ] } - ].forEach( ( { name, spec, expected } ) => { + ].forEach( ( { name, spec, expected } ) => QUnit.test( name, ( assert ) => { const template = newTemplateModel(); @@ -172,8 +174,8 @@ const serialization = template.serialize(); assert.deepEqual( Object.keys( serialization.template.params ), expected ); - } ); - } ); + } ) + ); [ { @@ -277,7 +279,7 @@ '' ] } - ].forEach( ( { name, spec, expected } ) => { + ].forEach( ( { name, spec, expected } ) => QUnit.test( 'getOrderedParameterNames: ' + name, ( assert ) => { const template = newTemplateModel(); @@ -286,8 +288,8 @@ } assert.deepEqual( template.getOrderedParameterNames(), expected ); - } ); - } ); + } ) + ); [ { @@ -405,7 +407,7 @@ '' ] } - ].forEach( ( { name, spec, expected } ) => { + ].forEach( ( { name, spec, expected } ) => QUnit.test( 'getAllParametersOrdered: ' + name, ( assert ) => { const template = newTemplateModel(); @@ -414,6 +416,7 @@ } assert.deepEqual( template.getAllParametersOrdered(), expected ); - } ); - } ); + } ) + ); + }() ); diff --git a/modules/ve-mw/tests/ui/widgets/ve.ui.MWParameterCheckboxInputWidget.test.js b/modules/ve-mw/tests/ui/widgets/ve.ui.MWParameterCheckboxInputWidget.test.js index 1de96beacb..4caf91d828 100644 --- a/modules/ve-mw/tests/ui/widgets/ve.ui.MWParameterCheckboxInputWidget.test.js +++ b/modules/ve-mw/tests/ui/widgets/ve.ui.MWParameterCheckboxInputWidget.test.js @@ -13,21 +13,25 @@ QUnit.test( 'Constructor passes config to parent', ( assert ) => { [ '', false, 'empty string' ], [ '2', false, 'unexpected string' ], [ true, false, 'unexpected type' ] -].forEach( ( [ value, expected, message ] ) => QUnit.test( `setValue( ${message} )`, ( assert ) => { - const widget = new ve.ui.MWParameterCheckboxInputWidget(); - widget.setValue( value ); +].forEach( ( [ value, expected, message ] ) => + QUnit.test( `setValue( ${message} )`, ( assert ) => { + const widget = new ve.ui.MWParameterCheckboxInputWidget(); + widget.setValue( value ); - assert.strictEqual( widget.isSelected(), expected ); - assert.strictEqual( widget.getValue(), expected ? '1' : '0' ); -} ) ); + assert.strictEqual( widget.isSelected(), expected ); + assert.strictEqual( widget.getValue(), expected ? '1' : '0' ); + } ) +); [ true, false -].forEach( ( value ) => QUnit.test( `setSelected( ${value} )`, ( assert ) => { - const widget = new ve.ui.MWParameterCheckboxInputWidget(); - widget.setSelected( value ); +].forEach( ( value ) => + QUnit.test( `setSelected( ${value} )`, ( assert ) => { + const widget = new ve.ui.MWParameterCheckboxInputWidget(); + widget.setSelected( value ); - assert.strictEqual( widget.isSelected(), value ); - assert.strictEqual( widget.getValue(), value ? '1' : '0' ); -} ) ); + assert.strictEqual( widget.isSelected(), value ); + assert.strictEqual( widget.getValue(), value ? '1' : '0' ); + } ) +);