Skip to content

Let simple array data in test.each() serve as automatic labels #1733

@Krinkle

Description

@Krinkle

Follows-up #1568

What are you trying to do?

Code that reproduces the problem:

QUnit.test.each( 'escapeRegExp [specials]', [
	'foo',
	'bar',
	'_',
	'+',
	'-',
	'^',
	'$'
], function ( assert, str ) {
	assert.propEqual(
		str.match( new RegExp( mw.util.escapeRegExp( str ) ) ),
		[ str ],
		'confirm correct escaping by being able to match itself'
	);
} );
Screenshot

What actually happened?

  • mytest [0]
  • mytest [1]
  • mytest [2].

What did you expect to happen?

For simple cases like this, it would be valuable if we let values serve as the test case label. In other words as:

  • mytest [foo]
  • mytest [bar]
  • mytest [_]

Example

EDIT: Example based on the implementation at #1799.

Before

TAP version 13
ok 1 array of strings [0]
ok 2 array of strings [1]
ok 3 array of strings [2]
ok 4 array of strings [3]

ok 13 array of mixed [0]
ok 14 array of mixed [1]
ok 15 array of mixed [2]
ok 16 array of mixed [3]
ok 17 array of mixed [4]
ok 18 array of mixed [5]
ok 19 array of mixed [6]
ok 20 array of mixed [7]
ok 21 array of mixed [8]
ok 22 array of mixed [9]
ok 23 array of mixed [10]

ok 27 keyed objects [caseFoo]
ok 28 keyed objects [caseBar]

After

TAP version 13
ok 1 array of strings [foo]
ok 2 array of strings [xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx]
ok 3 array of strings [$]
ok 4 array of strings [http://example.org]

ok 13 array of mixed [0: undefined]
ok 14 array of mixed [1: null]
ok 15 array of mixed [2: false]
ok 16 array of mixed [3: true]
ok 17 array of mixed [4: 0]
ok 18 array of mixed [5: 1]
ok 19 array of mixed [6: -10]
ok 20 array of mixed [7: 3.3333333333333335]
ok 21 array of mixed [8: 1e+43]
ok 22 array of mixed [9: Infinity]
ok 23 array of mixed [10: NaN]

ok 27 keyed objects [caseFoo]
ok 28 keyed objects [caseBar]

Metadata

Metadata

Assignees

Labels

Component: CoreFor module, test, hooks, and reporters.Type: EnhancementNew idea or feature request.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions