Skip to content

Pre-bind assertion methods #1592

Closed
Closed
@sindresorhus

Description

@sindresorhus

Or simply all methods on the test context t.

I didn't really buy the use-case in #1255, but after that I've encountered some situations where it could have been useful.

Sometimes I need to skip an assert based on some condition:

test(t => {
	const isTrue = condition ? t.true : t.skip.true;
	isTrue('a', 'b');
});

The above results in an error:

TypeError {
    message: 'Cannot read property \'_test\' of undefined',
  }

Or use a different assertion. I realize it's not a very good practice, but sometimes it's just the best way to do it.

Right now I have to do:

test(t => {
	const isTrue = (condition ? t.true : t.skip.true).bind(t);
	isTrue('a', 'b');
});

Which is not very nice.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions