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

testing: introduce fail function #123

Merged
merged 1 commit into from
Jan 26, 2019
Merged

testing: introduce fail function #123

merged 1 commit into from
Jan 26, 2019

Conversation

43081j
Copy link
Contributor

@43081j 43081j commented Jan 15, 2019

Introduces these two:

fail('some message'); // equivalent to assert(false, msg)
assert(throws(fn), true);

For now, throws returns a boolean and is expected to be used with assert just like equal.

If we want node compatibility, see #122 (throws does the assertion and throws the assertion error in node rather than returning a bool).

colors/test.ts Outdated
@@ -7,17 +7,13 @@ test(function singleColor() {
});

test(function doubleColor() {
assertEqual(color.red.bgBlue("Hello world"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file changed because i ran prettier across it FYI

@hayd
Copy link
Contributor

hayd commented Jan 15, 2019

I know this is part of #122, but perhaps we could discuss the renaming independently of this.

IMO assertThrows(fn, err?) throwing an assertion error (optionally of type/equal to err) seems desirable.

@43081j
Copy link
Contributor Author

43081j commented Jan 15, 2019

It depends really on what our aim is with naming of test functions.

If we agree on following the pattern of all assert* functions asserting, and all unprefixed functions returning bools then yes we should have an assertThrows (alongside the boolean unprefixed function).

It'd be three args in that case, (fn, err?, msg?).

If however we did end up following node and making all functions assert, there'd just be the one function with the assertion added inside.

@ry
Copy link
Member

ry commented Jan 15, 2019

I think it makes sense to move asserts to the node-style API. I wrote the asserts lib - so biased.
However for now please rename to assertThrows.

Let's do the reorganization to a Node-style API later - and after others have had a chance to chime in (ping @piscisaureus)

@43081j
Copy link
Contributor Author

43081j commented Jan 15, 2019

Do note that this pr defines it as a boolean function to be used with the assert function.

So if we rename it, we also want it to throw like assert does, right?

@ry
Copy link
Member

ry commented Jan 16, 2019

Do note that this pr defines it as a boolean function to be used with the assert function.

Remove it please

@kitsonk
Copy link
Contributor

kitsonk commented Jan 16, 2019

Sorry for the double PRs (#124) but I mention in the other PR that I already had something on my local machine because I was frustrated last night when writing some tests.

I think we should decorate assert with additional functions, as that is more common. My PR also has a few more features that brings it in line with something like Chai for the assert.throws().

@43081j
Copy link
Contributor Author

43081j commented Jan 16, 2019

The original reason for this PR still exists: a fail function.

Will rebase onto master when i get chance too.

Alsoo @kitsonk see #122.

Copy link
Contributor

@dsseng dsseng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting feature!

@43081j
Copy link
Contributor Author

43081j commented Jan 19, 2019

anyhow, updated this to be just fail in case you still want it.

@ry
Copy link
Member

ry commented Jan 24, 2019

I'm going to close this one since assert.throws was added in 9a3eb20
Thanks @43081j

@ry ry closed this Jan 24, 2019
@43081j
Copy link
Contributor Author

43081j commented Jan 24, 2019

@ry fail is still in here.. i had rebased and stripped it down to only the fail method.

@ry ry reopened this Jan 24, 2019
@ry
Copy link
Member

ry commented Jan 24, 2019

@43081j Oops - can you rebase once more? LGTM

@43081j
Copy link
Contributor Author

43081j commented Jan 26, 2019

@ry rebased

@43081j 43081j changed the title testing: introduce fail and throws functions testing: introduce fail function Jan 26, 2019
Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks : )

@ry ry merged commit c1c18c9 into denoland:master Jan 26, 2019
ry pushed a commit to ry/deno that referenced this pull request Oct 9, 2019
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

Successfully merging this pull request may close these issues.

5 participants