- Notifications
You must be signed in to change notification settings - Fork 1.4k
Add comments for assert and test interface definitions #1719
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
Add comments for assert and test interface definitions #1719
Conversation
cca9e69 to ed4dcba Compare
novemberborn left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kugtong33!
I've commented with some suggestions and questions. Perhaps if you give this another pass I can then push a commit with my edits? When it comes to documentation the back and forth in PR comments can be quite frustrating for everybody involved so I don't want to make it to burdensome on you (or perhaps I'm too particular about it).
Could you share a gif like you made in #1686 that shows the descriptions? Is readability increased if you use back ticks when referring to arguments?
index.d.ts Outdated
| export interface Assertions { | ||
| // Assert that actual is deep equal to expected | ||
| deepEqual<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void; | ||
| // Failing assertion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps "Cause the test to fail"?
index.d.ts Outdated
| id?: string; | ||
| } | ||
| | ||
| // When an assert fail, the message string will be shown in the error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this ever be shown to the user? I agree that we shouldn't document it for each assertion though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using vscode 1.20.1, this is not shown, but I think it is for the better to document the message parameter on each method definition
index.d.ts Outdated
| fail(message?: string): void; | ||
| // Assert that actual is equal to false | ||
| false(actual: any, message?: string): void; | ||
| // Assert that actual is falsy (false, 0, '', "", null, undefined, NaN) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to include "" in this list.
index.d.ts Outdated
| falsy(actual: any, message?: string): void; | ||
| // Assert that error is falsy | ||
| ifError(error: any, message?: string): void; | ||
| // Assert that actual is equal to expected (use deepEqual for objects/arrays) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps "strictly equal". Using this with objects or arrays can be a valid use case so the reference to deepEqual seems distracting. There's also edge cases with negative zero and NaN but that's perhaps too detailed for inline documentation 😉
index.d.ts Outdated
| not<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void; | ||
| // Assert that actual is not deep equal to expected | ||
| notDeepEqual<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void; | ||
| // Assert that string does not follow the regex pattern |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"match" rather than "follow"
index.d.ts Outdated
| notDeepEqual<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void; | ||
| // Assert that string does not follow the regex pattern | ||
| notRegex(string: string, regex: RegExp, message?: string): void; | ||
| // Assert that a function that never returns does not throw an error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "never returning" part is a type detail that's not relevant to the documentation. It's so that you can write t.notThrows(() => { throw new Error() }) without type errors.
index.d.ts Outdated
| notThrows(value: () => ObservableLike, message?: string): Promise<void>; | ||
| // Assert that a function that returns a promise does not throw an error | ||
| notThrows(value: () => PromiseLike<any>, message?: string): Promise<void>; | ||
| // Assert that a function that returns any value does not throw an error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly here, returning "any value" is besides the point. Just "Assert that a function does not throw." is sufficient.
index.d.ts Outdated
| (title: string, macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void; | ||
| (macro: Macro<Context> | Macro<Context>[], ...args: Array<any>): void; | ||
| | ||
| // Test hook that runs after all tests are done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try and describe what the modifier does, rather than what it is. E.g. here "Specify hooks that run once all tests have completed". Or below, "Skip this test."
71f9e60 to 56fd1f1 Compare | @novemberborn , apologies if I didn't got it right away (that it needs to be shown in the editor somehow), I think it is better if we use jsdoc |
| I don't know… it's a bother to write and not all that readable in the tooltips. Given that the method signature is shown, referring to the variables should be sufficient IMHO. Personally I'd love to see a succinct summary of what the assertion does. Specifics can be found in the online documentation. With the |
56fd1f1 to 6bfe9ba Compare 6bfe9ba to 363a004 Compare | @novemberborn , my second take on this, missing documentation on |
* Refactor the `Assertion` interface so the `.skip()` modifier can be added to each assertion. * Refactor the `ExecutionContext` interface to remove top-level `.skip` and allow `.log()` and `.plan()` to be skipped. * Add error value to `.end()` in `CbExecutionContext`. * Allow plain implementations to be passed to hooks without a title * Document all assertions, execution context methods and hook & test declarations and modifiers. * Explode the `t.throws()` definitions to give better information depending on how the assertion is used. * Link to documentation where appropriate.
| Thanks @kugtong33. I've pushed an updated TS definition. I may have gone overboard a little…
What do you think? I like how, when writing tests, the documentation tells you what the functions do. I suppose it reads a bit different from other API docs but I think it's more useful for AVA. How did you do your screen recordings? I haven't updated the Flow definition yet, and the changes I made mean it's a bit trickier to copy things across. I feel I can barely ask if you'd be up for doing that… but are you? 😄 |
| @novemberborn , absolutely yes, I will look into the new updates and implement it on the flow definitions I am using peek for the screen recordings |
| Is it necessary to restructure the flow definitions, that it would closely resemble the typescript definitions? |
| @kugtong33 that would be ideal. It makes it easier to update both files when we add features, since you can diff them against each other and see where you need to make changes. |
| Restructured flow definition with what I understood, certain definitions that I directly copied from the ts file doesn't work with flow, but I tried it to be as close as possible. Will add screen captures tomorrow P.S. |
| Wow great work @kugtong33! I've previously had trouble getting Flow to work well for me. If you can see the right descriptions then I'm happy. I did push one minor tweak.
That'd be great to have. It's just a lot of use cases to write 😄 |
That difference is fine I think. I tried |







Fixes #1686
Re-add deleted comments on the assert definition methods and added comments on the test interface definitions.
We can discuss the remaining definitions as I am not sure how to proceed from here.