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

Alias names to ".true" and ".false". #288

Closed
jamen opened this issue Nov 30, 2015 · 4 comments
Closed

Alias names to ".true" and ".false". #288

jamen opened this issue Nov 30, 2015 · 4 comments

Comments

@jamen
Copy link

jamen commented Nov 30, 2015

These are tokens, so in some usages they fail...

For instance with how I use AVA, I destructure the functions at the top. This way I don't have to prefix every operation with t. (which looks ugly in my opinion). So I do this:

test('test name', ({is, same, not}) => {
  // is(), same(), not()
});

But, whenever you when using functions with token-like names, it fails. For example, this destructuring fails getting .true:

test('test name', ({is, true, not}) => {
  // is(), true(), not()
});
SyntaxError: Unexpected token true
  at requireFromString (~/projects/rpv/node_modules/require-from-string/index.js:26:4)

Would be nice if there were some alias functions for any token-similar named functions for cases like this... .true() and .false()

@jamen jamen changed the title Alternative names to ".true" and ".false". Alias names to ".true" and ".false". Nov 30, 2015
@jamen
Copy link
Author

jamen commented Nov 30, 2015

I was playing around and discovered if you reassign the name in the destruction it doesn't fail. For instance:

test('test name', ({is, true: isTrue}) => {
  // is(), isTrue()
});

This does not throw.

So you can choose to merge #290 or not.

@jamestalmage
Copy link
Contributor

It seems like you have found a good solution to your problem. I don't think it is a good idea for us to start aliasing methods. Eventually we will introduce the ability to fully integrate custom assertions. When that happens, you will be able to modify our default assert plugin with the aliases you desire and apply it once across your entire project.

@sindresorhus
Copy link
Member

I don't see the point of using destructuring when it's more verbose than just doing t.true(). We're also not interested in adding aliases as we want to keep it consistent.

#114 (comment)

@jamen
Copy link
Author

jamen commented Dec 1, 2015

Sounds good 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants