This repository was archived by the owner on Sep 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 148
Add t.step_func_done documentation #186
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,23 +76,26 @@ Assertions can be added to the test by calling the step method of the test | |
| object with a function containing the test assertions: | ||
|
|
||
| ```js | ||
| t.step(function() {assert_true(true)}); | ||
| t.step(function() {assert_equals(1+1, 2)}); | ||
| ``` | ||
|
|
||
| When all the steps are complete, the done() method must be called: | ||
| When all the steps are complete, the `done()` method must be called: | ||
|
|
||
| ```js | ||
| t.done(); | ||
| ``` | ||
|
|
||
| As a convenience, async_test can also takes a function as first argument. | ||
| As a convenience, `async_test` can also takes a function as first argument. | ||
| This function is called with the test object as both its `this` object and | ||
| first argument. The above example can be rewritten as: | ||
| first argument. Thus we can write: | ||
|
|
||
| ```js | ||
| async_test(function(t) { | ||
| object.some_event = function() { | ||
| t.step(function (){assert_true(true); t.done();}); | ||
| object.some_event = function(e) { | ||
| t.step(function() { | ||
| assert_true(e.a); | ||
| t.done(); | ||
| }); | ||
| }; | ||
| }, "Simple async test"); | ||
| ``` | ||
|
|
@@ -120,6 +123,14 @@ object.some_event = t.unreached_func("some_event should not fire"); | |
| Keep in mind that other tests could start executing before an Asynchronous | ||
| Test is finished. | ||
|
|
||
| Finally, for cases where you want to simply pass the test when a callback is | ||
| called, there is `step_func_done`, which will generate a step function that | ||
| calls `done()`. For example: | ||
|
|
||
| ```js | ||
| object.some_event = t.step_func_done(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that t.step_func_done(f)is roughly equivalent to t.step_func(() => {
f();
t.done();
}) |
||
| ``` | ||
|
|
||
| ## Promise Tests ## | ||
|
|
||
| `promise_test` can be used to test APIs that are based on Promises: | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Indentation is weird here