Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-bind assertion methods #1592

Closed
sindresorhus opened this issue Nov 17, 2017 · 5 comments
Closed

Pre-bind assertion methods #1592

sindresorhus opened this issue Nov 17, 2017 · 5 comments

Comments

@sindresorhus
Copy link
Member

sindresorhus commented Nov 17, 2017

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.

@novemberborn
Copy link
Member

Yea we can give it a shot. It's a bunch more function allocations so it'd be interesting to see what happens when there's loads of tests in a single file, but on the other hand I doubt it'll really have an impact, especially in the most recent Node.js.

@reddysridhar53
Copy link

reddysridhar53 commented Jan 9, 2018

Can I work on this?

@novemberborn
Copy link
Member

@reddysridhar53 it's all yours!

@irahulcse
Copy link

How to do the work on this project?

@sindresorhus
Copy link
Member Author

@irahulcse You mean how to contribute? See our comprehensive contribution guide: https://github.com/avajs/ava/blob/master/contributing.md

@novemberborn novemberborn self-assigned this Feb 10, 2018
novemberborn added a commit that referenced this issue Feb 11, 2018
Assertions are now bound. Fixes #1592.

Assertions are now skipped by calling `.skip()` at the end, e.g.
`t.fail.skip()`. This is consistent with the test interface, where
`skip()` can only be used at the end of the chain.

The private `t._test` value has been removed. Instead a WeakMap is used
internally to look up the corresponding Test instance given an
ExecutionContext.
novemberborn added a commit that referenced this issue Feb 11, 2018
Assertions are now bound. Fixes #1592.

Assertions are now skipped by calling `.skip()` at the end, e.g.
`t.fail.skip()`. This is consistent with the test interface, where
`skip()` can only be used at the end of the chain.

The private `t._test` value has been removed. Instead a WeakMap is used
internally to look up the corresponding Test instance given an
ExecutionContext.
novemberborn added a commit that referenced this issue Feb 12, 2018
Assertions are now bound. Fixes #1592.

Assertions are now skipped by calling `.skip()` at the end, e.g.
`t.fail.skip()`. This is consistent with the test interface, where
`skip()` can only be used at the end of the chain.

The private `t._test` value has been removed. Instead a WeakMap is used
internally to look up the corresponding Test instance given an
ExecutionContext.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants