❗ Deprecation Notice |
---|
We want to express our sincere gratitude for your support and contributions to this open source project. As we are no longer using this technology internally, we have come to the decision to archive this repository. While we won't be providing further updates or support, the existing code and resources will remain accessible for your reference. We encourage anyone interested to fork the repository and continue the project's legacy independently. Thank you for being a part of this journey and for your patience and understanding. |
enzyme consumer for react-component-variations
import React from 'react';
import { expect } from 'chai';
import { render as staticRender, shallow } from 'enzyme';
import wrap from 'jest-wrap';
import forEachVariation from 'react-component-variations/traversal/forEachVariation';
import fixtures from '../variations/fixtures'; // fixture data
const action = () => () => {}; // used by storybook
// a jest-wrap plugin (usually this would be in its own module)
const isDOM = typeof window !== 'undefined';
function withDOM() {
return isDOM
? this.extend('with DOM', {})
: this.extend('without DOM', {}).skip();
}
import enzymeTests from 'react-component-variations-consumer-enzyme';
enzymeTests((name, { title, validTest, noThrowTest }) => {
describe(`<${name}> ${title}`, () => {
validTest((description, testFn) => {
it(description, () => {
expect(testFn()).to.equal(true);
});
});
noThrowTest((description, testFn, requiresDOM = false) => {
if (requiresDOM) {
wrap().use(withDOM).it(description, () => {
expect(() => testFn()).not.to.throw();
});
} else {
it(description, () => {
expect(() => testFn()).not.to.throw();
});
}
});
});
}, {
getExtras() { return { action, fixtures }; },
});