1.0.191 • Published 3 years ago

wix-ui-test-utils v1.0.191

Weekly downloads
1,246
License
MIT
Repository
-
Last release
3 years ago

wix-ui-test-utils

A common test utils used within the different wix-ui packages

Generic test utils

The following helper functions can be used within the different wix-ui packages:

isClassExists

Returns true if a certain class exists on an element.

import {isClassExists} from 'wix-ui-test-utils/react-helpers';

const element = document.createElement('div');
element.classList.add('big');

isClassExists(element, 'big'); // true
isClassExists(element, 'small'); // false

sleep

Returns a promise that resolves after a given timeout.

import {sleep} from 'wix-ui-test-utils/react-helpers';

sleep(5000)
  .then(() => console.log('Hello world'));

async function foo() {
  await sleep(5000);
  console.log('Hello world');
}

makeControlled

A HOC that makes underlying component "controlled". The "controlled" element will be initiated with an initial value, invoke an onChange callback and will bind the passed prop functions.

import {mount} from 'enzyme';
import {makeControlled} from 'wix-ui-test-utils/react-helpers';

const UncontrolledInput = props => (
  <input {...props}/>
);

const ControlledInput = makeControlled(UncontrolledInput);
const component = mount(
  <ControlledInput
    value={initialValue}
  />
);

// ...

Protractor helpers

getStoryUrl

Returns the iframe URL of a storybook's story.

import {getStoryUrl} from 'wix-ui-test-utils/protractor';

const storyUrl = getStoryUrl('Components', 'DatePicker'); // 'iframe.html?selectedKind=...'
browser.get(storyUrl);

scrollToElement

Scroll the window to a given element location.

import {scrollToElement} from 'wix-ui-test-utils/protractor';

// `el` is a DOM node
scrollToElement(el);

hasEllipsis

Checks if the element's text has overflowed and displays ellipsis

import {hasEllipsis} from 'wix-ui-test-utils/protractor';

// `el` is a DOM node
expect(hasEllipsis(el)).toEqual(true);

hasAttribute

Checks if the element has attribute

import {hasAttribute} from 'wix-ui-test-utils/protractor';

// `el` is a DOM node
expect(hasAttribute(el, 'id')).toEqual(true);

waitForVisibilityOf

Wait until an element is visible.

import {waitForVisibilityOf} from 'wix-ui-test-utils/protractor';

waitForVisibilityOf(
  element,
  errorMsg, // error message to throw when failed
  timeout // timeout (in ms), default is 10000
);

mouseEnter

Move the mouse on the element.

import {mouseEnter} from 'wix-ui-test-utils/protractor';

mouseEnter(element);

mouseLeave

Move the mouse out of the element.

import {mouseLeave} from 'wix-ui-test-utils/protractor';

mouseLeave(element);

Testkit helpers

createDriverFactory

Accepts a component driver. Returns a new driver factory. An explanation of drivers can be viewd here.

import React from 'react';
import {createDriverFactory} from 'wix-ui-test-utils/driver-factory';
import {buttonDriverFactory} from './Button.driver';
import Button from './';

const createDriver = createDriverFactory(buttonDriverFactory);

describe('Button', () => {
  it('should exist', () => {
    const driver = createDriver(<Button />);
    expect(driver.exists()).toBe(true);
  });
});

Vanilla (react-test-utils)

testkitFactoryCreator

Accepts a component driver. Returns a testkit factory.

import {testkitFactoryCreator} from 'wix-ui-test-utils/vanilla';
import datePickerDriverFactory './driver';

const driverFactory = testkitFactoryCreator(datePickerDriverFactory);
const driver = driverFactory({
  // ...
});

driver.click();
driver.exists();
// ...

isTestkitExists

This function should be used inside the component tests in order to to perform a sanity check for the exposed testkit. It accepts a React Element and a testkit factory. Returns true if the driver works as expected.

import {testkitFactoryCreator, isTestkitExists} from 'wix-ui-test-utils/vanilla';
import datePickerDriverFactory './driver';

const driverFactory = testkitFactoryCreator(datePickerDriverFactory);

isTestkitExists(
  <DatePicker />,
  driverFactory
); // true

Enzyme

enzymeTestkitFactoryCreator

Accepts a component driver. Returns a testkit factory based on enzyme.

import {enzymeTestkitFactoryCreator} from 'wix-ui-test-utils/enzyme';
import datePickerDriverFactory './driver';

const driverFactory = enzymeTestkitFactoryCreator(datePickerDriverFactory);
const driver = driverFactory({
  // ...
});

driver.click();
driver.exists();
// ...

isEnzymeTestkitExists

This function should be used inside the component tests in order to to perform a sanity check for the exposed testkit. It accepts a React Element and a testkit factory. Returns true if the driver works as expected.

import {enzymeTestkitFactoryCreator, isEnzymeTestkitExists} from 'wix-ui-test-utils/enzyme';
import datePickerDriverFactory './driver';
import {mount} from 'enzyme';

const driverFactory = enzymeTestkitFactoryCreator(datePickerDriverFactory);

isEnzymeTestkitExists(
  <DatePicker />,
  driverFactory,
  mount
); // true

Protractor

protractorTestkitFactoryCreator

Accepts a component driver. Returns a testkit factory for protractor.

import {protractorTestkitFactoryCreator} from 'wix-ui-test-utils/protractor';
import datePickerDriverFactory './driver';

const driverFactory = protractorTestkitFactoryCreator(datePickerDriverFactory);
const driver = driverFactory({dataHook: 'date-picker'});

driver.click();
driver.exists();
// ...
1.0.191

3 years ago

1.0.190

3 years ago

1.0.186

3 years ago

1.0.185

3 years ago

1.0.184

3 years ago

1.0.183

4 years ago

1.0.182

4 years ago

1.0.181

4 years ago

1.0.180

4 years ago

1.0.179

4 years ago

1.0.178

5 years ago

1.0.177

5 years ago

1.0.176

5 years ago

1.0.175

5 years ago

1.0.174

5 years ago

1.0.173

5 years ago

1.0.172

6 years ago

1.0.171

6 years ago

1.0.170

6 years ago

1.0.169

6 years ago

1.0.168

6 years ago

1.0.167

6 years ago

1.0.166

6 years ago

1.0.165

6 years ago

1.0.164

6 years ago

1.0.163

6 years ago

1.0.162

6 years ago

1.0.161

6 years ago

1.0.160

6 years ago

1.0.159

6 years ago

1.0.158

6 years ago

1.0.157

6 years ago

1.0.156

6 years ago

1.0.155

6 years ago

1.0.154

6 years ago

1.0.153

6 years ago

1.0.152

6 years ago

1.0.151

6 years ago

1.0.150

6 years ago

1.0.149

6 years ago

1.0.148

6 years ago

1.0.147

6 years ago

1.0.146

6 years ago

1.0.145

6 years ago

1.0.144

6 years ago

2.0.0

6 years ago

1.0.143

6 years ago

1.0.142

6 years ago

1.0.141

6 years ago

1.0.140

6 years ago

1.0.139

6 years ago

1.0.138

6 years ago

1.0.137

6 years ago

1.0.136

6 years ago

1.0.135

6 years ago

1.0.134

6 years ago

1.0.133

6 years ago

1.0.132

6 years ago

1.0.131

6 years ago

1.0.130

6 years ago

1.0.129

6 years ago

1.0.128

7 years ago

1.0.127

7 years ago

1.0.126

7 years ago

1.0.125

7 years ago

1.0.124

7 years ago

1.0.123

7 years ago

1.0.122

7 years ago

1.0.121

7 years ago

1.0.120

7 years ago

1.0.119

7 years ago

1.0.118

7 years ago

1.0.117

7 years ago

1.0.116

7 years ago

1.0.115

7 years ago

1.0.114

7 years ago

1.0.113

7 years ago

1.0.112

7 years ago

1.0.111

7 years ago

1.0.110

7 years ago

1.0.109

7 years ago

1.0.108

7 years ago

1.0.107

7 years ago

1.0.106

7 years ago

1.0.105

7 years ago

1.0.104

7 years ago

1.0.103

7 years ago

1.0.102

7 years ago

1.0.101

7 years ago

1.0.100

7 years ago

1.0.99

7 years ago

1.0.98

7 years ago

1.0.97

7 years ago

1.0.96

7 years ago

1.0.95

7 years ago

1.0.94

7 years ago

1.0.93

7 years ago

1.0.92

7 years ago

1.0.91

7 years ago

1.0.90

7 years ago

1.0.89

7 years ago

1.0.88

7 years ago

1.0.87

7 years ago

1.0.86

7 years ago

1.0.85

7 years ago

1.0.84

7 years ago

1.0.83

7 years ago

1.0.82

7 years ago

1.0.81

7 years ago

1.0.80

7 years ago

1.0.79

7 years ago

1.0.78

7 years ago

1.0.77

7 years ago

1.0.76

7 years ago

1.0.75

7 years ago

1.0.74

7 years ago

1.0.73

7 years ago

1.0.72

7 years ago

1.0.71

7 years ago

1.0.70

7 years ago

1.0.69

7 years ago

1.0.68

7 years ago

1.0.67

7 years ago

1.0.66

7 years ago

1.0.65

7 years ago

1.0.64

7 years ago

1.0.63

7 years ago

1.0.62

7 years ago

1.0.61

7 years ago

1.0.60

7 years ago

1.0.59

7 years ago

1.0.58

7 years ago

1.0.57

7 years ago

1.0.56

7 years ago

1.0.55

7 years ago

1.0.54

7 years ago

1.0.53

7 years ago

1.0.52

7 years ago

1.0.51

7 years ago

1.0.50

7 years ago

1.0.49

7 years ago

1.0.48

7 years ago

1.0.47

7 years ago

1.0.46

7 years ago

1.0.45

7 years ago

1.0.44

7 years ago

1.0.43

7 years ago

1.0.42

7 years ago

1.0.41

7 years ago

1.0.40

7 years ago

1.0.39

7 years ago

1.0.38

7 years ago

1.0.37

7 years ago

1.0.36

7 years ago

1.0.35

7 years ago

1.0.34

7 years ago

1.0.33

7 years ago

1.0.32

7 years ago

1.0.31

7 years ago

1.0.30

7 years ago

1.0.29

7 years ago

1.0.28

7 years ago

1.0.27

7 years ago

1.0.26

7 years ago

1.0.25

7 years ago

1.0.24

7 years ago

1.0.23

7 years ago

1.0.22

7 years ago

1.0.21

7 years ago

1.0.20

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

8 years ago

1.0.15

8 years ago

1.0.14

8 years ago

1.0.13

8 years ago

1.0.12

8 years ago

1.0.11

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago