https://github.com/testdouble/ought
A dumb assertion library with smart diffs for JavaScript
https://github.com/testdouble/ought
Last synced: about 2 months ago
JSON representation
A dumb assertion library with smart diffs for JavaScript
- Host: GitHub
- URL: https://github.com/testdouble/ought
- Owner: testdouble
- Created: 2019-02-18T23:39:01.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2022-02-11T16:05:49.000Z (about 4 years ago)
- Last Synced: 2025-08-09T12:50:36.578Z (8 months ago)
- Language: JavaScript
- Size: 58.6 KB
- Stars: 34
- Watchers: 51
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ought
This module combines your underlying Node.js runtime's
[assert](https://nodejs.org/api/assert.html) module's assertions with the
pleasant diffing output from the [ava](https://github.com/avajs/ava) test
runner (which is actually powered by
[concordance](https://github.com/concordancejs/concordance)).
To avoid adding unnecessary overhead to your tests, ought goes out of its way to
not `require` any of its diffing and printing dependencies unless one of your
assertions has actually failed.
## Usage
Install it:
```
npm install -D ought
```
Use it:
```js
const ought = require('ought')
module.exports = function myTest () {
const result = 34 + 43
ought.equal(result, 77)
}
```
The other method is `ought.notEqual`.
## API
### Assertions
* `ought.equal(actual, expected, message)` - Other than the pretty failure
message, behavior should exactly match
[assert.deepStrictEqual](https://nodejs.org/api/assert.html#assert_assert_deepstrictequal_actual_expected_message)
* `ought.notEqual(actual, expected, message)` - This one just calls [assert.notDeepStrictEqual](https://nodejs.org/api/assert.html#assert_assert_notdeepstrictequal_actual_expected_message)
We would've kept the original assertion names, but we hate typing.
### Configuration
You can configure ought with `ought.config`. Defaults follow:
```js
ought.config({
color: true
})
```
## Output
What does the output look like? The theme's colors need some tweaking, but for
now the output of
[test.js](https://github.com/testdouble/ought/blob/a0bfcb69c3d06f4cdff86649010479a387852915/test.js#L5-L33)'s
failing test looks like this:

## Code of Conduct
This project follows Test Double's [code of conduct](https://testdouble.com/code-of-conduct) for all community interactions, including (but not limited to) one-on-one communications, public posts/comments, code reviews, pull requests, and GitHub issues. If violations occur, Test Double will take any action they deem appropriate for the infraction, up to and including blocking a user from the organization's repositories.