Skip to content

Add testcafe-testing-library #88

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

Merged
merged 7 commits into from
Apr 27, 2019
Merged
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
64 changes: 64 additions & 0 deletions docs/testcafe-testing-library/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
id: intro
title: Testcafe Testing Library
---

[`testcafe-testing-library`][gh] allows the use of dom-testing queries within
[Testcafe](https://devexpress.github.io/testcafe/) cross-browser end-to-end web
testing.

```
npm install --save-dev testcafe testcafe-testing-library
```

- [testcafe-testing-library on GitHub][gh]

## Usage

`testcafe-testing-library` provides custom Selectors allowing you to query the
dom.

Add `testcafe-testing-library` to your test fixture's `beforeEach` hook:

```javascript
import {
getByText, //or any other queries you want
addTestcafeTestingLibrary,
} from 'testcafe-testing-library'

fixture`selectors`.beforeEach(addTestcafeTestingLibrary)
.page`http://localhost:13370`
```

You can now import & use `getBy`, `getAllBy`, `queryBy` and `queryAllBy`
selectors in your tests.
[See `dom-testing-library` API for reference](dom-testing-library/api-queries.md)

## Examples

To show some simple examples (from
[https://github.com/benmonro/testcafe-testing-library/blob/master/tests/testcafe/selectors.js](https://github.com/benmonro/testcafe-testing-library/blob/master/tests/testcafe/selectors.js)):

```javascript
test('getByPlaceHolderText', async t => {
await t.typeText(
getByPlaceholderText('Placeholder Text'),
'Hello Placeholder'
)
})
test('getByText', async t => {
await t.click(getByText('getByText'))
})

test('getByLabelText', async t => {
await t.typeText(
getByLabelText('Label For Input Labelled By Id'),
'Hello Input Labelled By Id'
)
})
```

**_Note:_** The selectors come pre-bound to `document.body`, so no need to
provide a container.

[gh]: https://github.com/benmonro/testcafe-testing-library
1 change: 1 addition & 0 deletions website/sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"vue-testing-library/intro",
"angular-testing-library/intro",
"pptr-testing-library/intro",
"testcafe-testing-library/intro",
{
"type": "subcategory",
"label": "ReasonReact Testing Library",
Expand Down