wix-style-react
Version:
wix-style-react
106 lines (78 loc) • 3.04 kB
Markdown
> Button
| method | arguments | returned value | description |
| -------------------- | --------- | -------------- | ---------------------------------- |
| exists | - | boolean | returns true if element in the DOM |
| element | - | element | returns the component element |
| click | - | - | clicks on the button |
| getButtonTextContent | - | string | returns the button text |
| isButtonDisabled | - | boolean | returns true if button is disabled |
```javascript
import React from 'react';
import ReactTestUtils from 'react-dom/test-utils';
import Button from 'wix-style-react/Button';
import { buttonTestkitFactory } from 'wix-style-react/dist/testkit';
const div = document.createElement('div');
const dataHook = 'myDataHook';
const component = (
<div>
<Button dataHook={dataHook} />
</div>
);
const wrapper = div.appendChild(
ReactTestUtils.renderIntoDocument(component, { dataHook })
);
const testkit = buttonTestkitFactory({ wrapper, dataHook });
//Do tests
describe('Element should exist', async () => {
expect(await testkit.exists()).toBeTruthy();
});
```
```javascript
import React from 'react';
import { mount } from 'enzyme';
import Button from 'wix-style-react/Button';
import { buttonTestkitFactory } from 'wix-style-react/dist/testkit/enzyme';
const dataHook = 'myDataHook';
const wrapper = mount(
<div>
<Button dataHook={dataHook} />
</div>
);
const testkit = buttonTestkitFactory({ wrapper, dataHook });
//Do tests
describe('Element should exist', async () => {
expect(await testkit.exists()).toBeTruthy();
});
```
> Element should be rendered with a data-hook into the DOM `<Button dataHook="myDataHook" />`
```javascript
import puppeteer from 'puppeteer';
import { buttonTestkitFactory } from 'wix-style-react/dist/testkit/puppeteer';
//puppeteer setup
const browser = await puppeteer.launch();
const page = await browser.newPage();
//Create an element testkit via the data-hook attribute
const testkit = await buttonTestkitFactory({ dataHook: 'myDataHook', page });
await page.goto('/page-where-button-appears'); //Your application url
//Do tests
describe('Element should exist', async () => {
expect(await testkit.exists()).toBeTruthy();
});
```
> Element should be rendered with a data-hook into the DOM `<Button dataHook="myDataHook" />`
```javascript
import { buttonTestkitFactory } from 'wix-style-react/dist/testkit/protractor';
//Create an element testkit via the data-hook attribute
const testkit = buttonTestkitFactory({ dataHook: 'myDataHook' });
await browser.get('/page-where-button-appears'); //Your application url
//Do tests
describe('Element should exist', async () => {
expect(await testkit.exists()).toBeTruthy();
});
```