Skip to content

Commit

Permalink
Add reset method to CanaryTest class
Browse files Browse the repository at this point in the history
  • Loading branch information
pineapplemachine committed Mar 28, 2018
1 parent 3adffbd commit 9fc35c6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions canary.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ class CanaryTest{
this.columnInLine = undefined;
}
}
// Reset the state of the test so that it is safe to run it again.
reset(){
this.attempted = false;
this.skipped = false;
this.success = undefined;
this.aborted = undefined;
this.startTime = undefined;
this.endTime = undefined;
this.errors = [];
}
// Mark the test and all its children as "TODO". These tests will not be
// attempted.
todo(){
Expand Down
26 changes: 26 additions & 0 deletions docs/api-advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,29 @@ Recursively run all the body functions assigned to test groups, but not to ordin

Group expansion is put off until tests are actually needed in order to make the startup performance impact of including tests in an application source file close to nonexistent, even in the case of testing code errors that could potentially cause hangups, since extremely little work is done at the time of declaration.

# reset

Resets the test's state so that it is safe to run it again.

**Examples:**

``` js
const someTest = canary.test("Example test", function(){
assert(1 + 1 === 2);
});
// Run the test once
canary.run().then(() => {
// Verify its success state
assert(someTest.attempted);
assert(someTest.success);
// Reset it
someTest.reset();
assert(!someTest.attempted);
assert(!someTest.success);
// Run it again
canary.run().then(() => {
assert(someTest.attempted);
assert(someTest.success);
});
});
```

0 comments on commit 9fc35c6

Please sign in to comment.