test Function
Declares a test.
Note
Tests belong to fixtures — make sure you declare a fixture before you declare a test!
test( testName, fn(t) ) → this
Parameter | Type | Description |
---|---|---|
| String | The name of the test. |
| Function | An asynchronous function that contains test code. |
| Object | The test controller object (necessary to access test API). |
fixture `My Fixture`;
test('Click a button', async t => {
await t.click('#button');
});
test('Type something', async t => {
await t.typeText('#comment', 'I love TestCafe')
});
The Test
object offers methods that configure the following:
- The test page URL
- Custom test metadata
- Test hooks
- JavaScript error handling options
You can also import the test object into your test file.
import { test } from 'testcafe';
fixture`Test import`
.page('https://devexpress.github.io/testcafe/example');
test('Click a button', async t => {
await t.click('#submit-button');
});