Skip to content

Assertions return boolean #2584

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

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ts-version: [~3.7.5, ~3.8, ~3.9]
ts-version: [~3.7.5, ~3.8, ~3.9, ~4.0]
steps:
- uses: actions/checkout@v1
with:
Expand Down
7 changes: 6 additions & 1 deletion ava.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
const skipTests = [];
if (process.versions.node < '12.14.0') {
skipTests.push('!test/configurable-module-format/module.js');
}

export default {
files: ['test/**', '!test/**/{fixtures,helpers}/**'],
files: ['test/**', '!test/**/{fixtures,helpers}/**', ...skipTests],
ignoredByWatcher: ['{coverage,docs,media,test-d,test-tap}/**']
};
4 changes: 2 additions & 2 deletions docs/02-execution-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Contains shared state from hooks.

## `t.passed`

Whether a test has passed. This value is only accurate in the `test.afterEach()` and `test.afterEach.always()` hooks.
When used in `test.afterEach()` or `test.afterEach.always()` hooks this tells you whether the test has passed. When used in a test itself (including teardown functions) this remains `true` until an assertion fails, the test has ended with an error, or a teardown function caused an error. This value has no meaning in other hooks.

## `t.end()`

Expand All @@ -36,7 +36,7 @@ Log values contextually alongside the test result instead of immediately printin

## `t.plan(count)`

Plan how many assertion there are in the test. The test will fail if the actual assertion count doesn't match the number of planned assertions. See [assertion planning](./03-assertions.md#assertion-planning).
Plan how many assertions there are in the test. The test will fail if the actual assertion count doesn't match the number of planned assertions. See [assertion planning](./03-assertions.md#assertion-planning).

## `t.teardown(fn)`

Expand Down
4 changes: 2 additions & 2 deletions docs/03-assertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ Assert that an error is thrown. `fn` must be a function which should throw. The
* `name`: the expected `.name` value of the thrown error
* `code`: the expected `.code` value of the thrown error

`expectation` does not need to be specified. If you don't need it but do want to set an assertion message you have to specify `null`.
`expectation` does not need to be specified. If you don't need it but do want to set an assertion message you have to specify `undefined`. (AVA 3 also allows you to specify `null`. This will be removed in AVA 4. You can opt into this change early by enabling the `disableNullExpectations` experiment.)

Example:

Expand Down Expand Up @@ -276,7 +276,7 @@ The thrown value *must* be an error. It is returned so you can run more assertio
* `name`: the expected `.name` value of the thrown error
* `code`: the expected `.code` value of the thrown error

`expectation` does not need to be specified. If you don't need it but do want to set an assertion message you have to specify `null`.
`expectation` does not need to be specified. If you don't need it but do want to set an assertion message you have to specify `undefined`. (AVA 3 also allows you to specify `null`. This will be removed in AVA 4. You can opt into this change early by enabling the `disableNullExpectations` experiment.)

Example:

Expand Down
23 changes: 22 additions & 1 deletion docs/06-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Arguments passed to the CLI will always take precedence over the CLI options con
- `tap`: if `true`, enables the [TAP reporter](./05-command-line.md#tap-reporter)
- `verbose`: if `true`, enables verbose output
- `snapshotDir`: specifies a fixed location for storing snapshot files. Use this if your snapshots are ending up in the wrong location
- `extensions`: extensions of test files. Setting this overrides the default `["cjs", "mjs", "js"]` value, so make sure to include those extensions in the list
- `extensions`: extensions of test files. Setting this overrides the default `["cjs", "mjs", "js"]` value, so make sure to include those extensions in the list. [Experimentally you can configure how files are loaded](#configuring-module-formats)
- `require`: extra modules to require before tests are run. Modules are required in the [worker processes](./01-writing-tests.md#process-isolation)
- `timeout`: Timeouts in AVA behave differently than in other test frameworks. AVA resets a timer after each test, forcing tests to quit if no new test results were received within the specified timeout. This can be used to handle stalled tests. See our [timeout documentation](./07-test-timeouts.md) for more options.
- `nodeArguments`: Configure Node.js arguments used to launch worker processes.
Expand Down Expand Up @@ -213,6 +213,27 @@ export default {
};
```

### Configuring module formats

Node.js can only load non-standard extension as ES Modules when using [experimental loaders](https://nodejs.org/docs/latest/api/esm.html#esm_experimental_loaders). To use this you'll also have to configure AVA to `import()` your test file.

This is still an experimental feature. You can opt in to it by enabling the `configurableModuleFormat` experiment. Afterwards, you'll be able to specify per-extension module formats using an object form.

As with the array form, you need to explicitly list `js`, `cjs`, and `mjs` extensions. These **must** be set using the `true` value; other extensions are configurable using either `'commonjs'` or `'module'`:

`ava.config.js`:
```js
export default {
nonSemVerExperiments: {
configurableModuleFormat: true
},
extensions: {
js: true,
ts: 'module'
}
};
```

## Node arguments

The `nodeArguments` configuration may be used to specify additional arguments for launching worker processes. These are combined with `--node-arguments` passed on the CLI and any arguments passed to the `node` binary when starting AVA.
Expand Down
2 changes: 1 addition & 1 deletion docs/recipes/debugging-with-vscode.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ You can use VS Code's “JavaScript Debug Terminal” to automatically debug AVA

## Creating a launch configuration

Alternatively you can create a lanch configuration, which makes it easier to debug individual test files.
Alternatively you can create a launch configuration, which makes it easier to debug individual test files.

1. Open a workspace for your project.
1. In the sidebar click the *Debug* handle.
Expand Down
49 changes: 44 additions & 5 deletions docs/recipes/react.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,59 @@ You can find more information in [`@ava/babel`](https://github.com/avajs/babel).

## Using [Enzyme](https://github.com/airbnb/enzyme)

Let's first see how to use AVA with one of the most popular React testing libraries: [Enzyme](https://github.com/airbnb/enzyme).
Let's first see how to use AVA with one of the most popular React testing libraries: [Enzyme](https://github.com/enzymejs/enzyme).

If you intend to only use [shallow component rendering](https://facebook.github.io/react/docs/test-utils.html#shallow-rendering), you don't need any extra setup.

First install [Enzyme required packages](https://github.com/airbnb/enzyme/#installation):
### Install Enzyme

First install [Enzyme and its required adapter](https://github.com/enzymejs/enzyme#installation):

```console
$ npm install --save-dev enzyme react-addons-test-utils react-dom
$ npm install --save-dev enzyme enzyme-adapter-react-16
```

### Set up Enzyme

Create a helper file, prefixed with an underscore. This ensures AVA does not treat it as a test.

`test/_setup-enzyme-adapter.js`:

```js
const Enzyme = require('enzyme');
const Adapter = require('enzyme-adapter-react-16');

Enzyme.configure({
adapter: new Adapter()
});
```

### Configure tests to use Enzyme

Configure AVA to `require` the helper before every test file.

**`package.json`:**

```json
{
"ava": {
"require": [
"./test/_setup-enzyme-adapter.js"
]
}
}
```

### Enjoy

Then you can use Enzyme straight away:

`test.js`:

```js
const test = require('ava');
const React = require('react');
const PropTypes = require('prop-types');
const {shallow} = require('enzyme');

const Foo = ({children}) =>
Expand All @@ -51,7 +89,7 @@ const Foo = ({children}) =>
</div>;

Foo.propTypes = {
children: React.PropTypes.any
children: PropTypes.any
};

test('has a .Foo class name', t => {
Expand Down Expand Up @@ -93,6 +131,7 @@ Usage example:
```js
const test = require('ava');
const React = require('react');
const PropTypes = require('prop-types');
const {renderJSX, JSX} = require('jsx-test-helpers');

const Foo = ({children}) =>
Expand All @@ -103,7 +142,7 @@ const Foo = ({children}) =>
</div>;

Foo.propTypes = {
children: React.PropTypes.any
children: PropTypes.any
};

test('renders correct markup', t => {
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ export interface CbExecutionContext<Context = unknown> extends ExecutionContext<
end(error?: any): void;
}

export type ImplementationResult = PromiseLike<void> | Subscribable | void; // eslint-disable-line @typescript-eslint/no-invalid-void-type
export type ImplementationResult = PromiseLike<void> | Subscribable | void;
export type Implementation<Context = unknown> = (t: ExecutionContext<Context>) => ImplementationResult;
export type CbImplementation<Context = unknown> = (t: CbExecutionContext<Context>) => ImplementationResult;

Expand Down
Loading