npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wix/wix-ui-test-utils

v1.1.11

Published

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

Downloads

4,808

Readme

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/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/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/wix-ui-test-utils/react-helpers';

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

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

// ...

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/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/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/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/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/wix-ui-test-utils/enzyme';
import datePickerDriverFactory './driver';
import {mount} from 'enzyme';

const driverFactory = enzymeTestkitFactoryCreator(datePickerDriverFactory);

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