1.0.191 • Published 2 years ago

wix-ui-test-utils v1.0.191

Weekly downloads
1,246
License
MIT
Repository
-
Last release
2 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

2 years ago

1.0.190

2 years ago

1.0.186

2 years ago

1.0.185

2 years ago

1.0.184

2 years ago

1.0.183

3 years ago

1.0.182

3 years ago

1.0.181

3 years ago

1.0.180

3 years ago

1.0.179

3 years ago

1.0.178

3 years ago

1.0.177

4 years ago

1.0.176

4 years ago

1.0.175

4 years ago

1.0.174

4 years ago

1.0.173

4 years ago

1.0.172

4 years ago

1.0.171

4 years ago

1.0.170

5 years ago

1.0.169

5 years ago

1.0.168

5 years ago

1.0.167

5 years ago

1.0.166

5 years ago

1.0.165

5 years ago

1.0.164

5 years ago

1.0.163

5 years ago

1.0.162

5 years ago

1.0.161

5 years ago

1.0.160

5 years ago

1.0.159

5 years ago

1.0.158

5 years ago

1.0.157

5 years ago

1.0.156

5 years ago

1.0.155

5 years ago

1.0.154

5 years ago

1.0.153

5 years ago

1.0.152

5 years ago

1.0.151

5 years ago

1.0.150

5 years ago

1.0.149

5 years ago

1.0.148

5 years ago

1.0.147

5 years ago

1.0.146

5 years ago

1.0.145

5 years ago

1.0.144

5 years ago

2.0.0

5 years ago

1.0.143

5 years ago

1.0.142

5 years ago

1.0.141

5 years ago

1.0.140

5 years ago

1.0.139

5 years ago

1.0.138

5 years ago

1.0.137

5 years ago

1.0.136

5 years ago

1.0.135

5 years ago

1.0.134

5 years ago

1.0.133

5 years ago

1.0.132

5 years ago

1.0.131

5 years ago

1.0.130

5 years ago

1.0.129

5 years ago

1.0.128

5 years ago

1.0.127

5 years ago

1.0.126

5 years ago

1.0.125

5 years ago

1.0.124

5 years ago

1.0.123

5 years ago

1.0.122

6 years ago

1.0.121

6 years ago

1.0.120

6 years ago

1.0.119

6 years ago

1.0.118

6 years ago

1.0.117

6 years ago

1.0.116

6 years ago

1.0.115

6 years ago

1.0.114

6 years ago

1.0.113

6 years ago

1.0.112

6 years ago

1.0.111

6 years ago

1.0.110

6 years ago

1.0.109

6 years ago

1.0.108

6 years ago

1.0.107

6 years ago

1.0.106

6 years ago

1.0.105

6 years ago

1.0.104

6 years ago

1.0.103

6 years ago

1.0.102

6 years ago

1.0.101

6 years ago

1.0.100

6 years ago

1.0.99

6 years ago

1.0.98

6 years ago

1.0.97

6 years ago

1.0.96

6 years ago

1.0.95

6 years ago

1.0.94

6 years ago

1.0.93

6 years ago

1.0.92

6 years ago

1.0.91

6 years ago

1.0.90

6 years ago

1.0.89

6 years ago

1.0.88

6 years ago

1.0.87

6 years ago

1.0.86

6 years ago

1.0.85

6 years ago

1.0.84

6 years ago

1.0.83

6 years ago

1.0.82

6 years ago

1.0.81

6 years ago

1.0.80

6 years ago

1.0.79

6 years ago

1.0.78

6 years ago

1.0.77

6 years ago

1.0.76

6 years ago

1.0.75

6 years ago

1.0.74

6 years ago

1.0.73

6 years ago

1.0.72

6 years ago

1.0.71

6 years ago

1.0.70

6 years ago

1.0.69

6 years ago

1.0.68

6 years ago

1.0.67

6 years ago

1.0.66

6 years ago

1.0.65

6 years ago

1.0.64

6 years ago

1.0.63

6 years ago

1.0.62

6 years ago

1.0.61

6 years ago

1.0.60

6 years ago

1.0.59

6 years ago

1.0.58

6 years ago

1.0.57

6 years ago

1.0.56

6 years ago

1.0.55

6 years ago

1.0.54

6 years ago

1.0.53

6 years ago

1.0.52

6 years ago

1.0.51

6 years ago

1.0.50

6 years ago

1.0.49

6 years ago

1.0.48

6 years ago

1.0.47

6 years ago

1.0.46

6 years ago

1.0.45

6 years ago

1.0.44

6 years ago

1.0.43

6 years ago

1.0.42

6 years ago

1.0.41

6 years ago

1.0.40

6 years ago

1.0.39

6 years ago

1.0.38

6 years ago

1.0.37

6 years ago

1.0.36

6 years ago

1.0.35

6 years ago

1.0.34

6 years ago

1.0.33

6 years ago

1.0.32

6 years ago

1.0.31

6 years ago

1.0.30

6 years ago

1.0.29

6 years ago

1.0.28

6 years ago

1.0.27

6 years ago

1.0.26

6 years ago

1.0.25

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.22

6 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago