Skip to content

Commit

Permalink
Refactor assertions
Browse files Browse the repository at this point in the history
* Use our own AssertionError class. Now we can track the assertion
rather than abusing the operator field. We can also stop depending on
`core-assert` once we implement `t.throws()` ourselves. Reserve the
`statements` property for power-assert output

* Directly create `AssertionError`s, making it easier to specify the
varying options

* Default the assertion message to an empty string, removing workarounds
in the mini and verbose reporters

* Improve `t.plan()` assertion errors. Specify 'plan' as the assertion,
and use `===` as the operator

* Refactor `t.throws()` and `t.notThrows()`, improving readability and
fixing #1227

* Move knowledge of when to show output into `serialize-error.js`. It
sat kind of awkwardly in `assert.js`

* Always try to format errors in mini and verbose reporters, check
if actual / expected values are available when formatting

* Wrap assertions in `assert.js` for use with the `ExecutionContext`

* Only enhance the power-assert assertions, don't use `empower-core`
to wrap the others

* Remove superfluous `empower-core` 'originalMessage' handling. Our
assertions create `AssertionError`s with the correct message

* Refactor overloaded `Test#_assert()` method and assertion tracking
internals. Note that only `t.throws()` and `notThrows()` are (possibly)
asynchronous
  • Loading branch information
novemberborn authored and sindresorhus committed Mar 14, 2017
1 parent 3aeb8b0 commit 4463f38
Show file tree
Hide file tree
Showing 16 changed files with 555 additions and 528 deletions.
2 changes: 1 addition & 1 deletion index.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type AssertContext = {
};
// Assert that function doesn't throw an error or promise resolves.
notThrows: {
<U>(value: PromiseLike<U>, message?: string): Promise<U>;
(value: PromiseLike<mixed>, message?: string): Promise<void>;
(value: () => mixed, message?: string): void;
};
// Assert that contents matches regex.
Expand Down
Loading

0 comments on commit 4463f38

Please sign in to comment.