UNPKG

redux-ab-test

Version:

A/B testing React components with Redux and debug tools. Isomorphic with a simple, universal interface. Well documented and lightweight. Tested in popular browsers and Node.js. Includes helpers for React, Redux, and Segment.io

92 lines (75 loc) 3.41 kB
'use strict'; var _extends2 = require('babel-runtime/helpers/extends'); var _extends3 = _interopRequireDefault(_extends2); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _reactTestRenderer = require('react-test-renderer'); var _reactTestRenderer2 = _interopRequireDefault(_reactTestRenderer); var _variation = require('./variation'); var _module = require('../../module'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } describe('(Component) src/components/variation/variation.js', function () { var component = void 0; var tree = void 0; var props = void 0; beforeEach(function () { var reduxAbTest = _module.initialState.merge({ 'experiments': [{ id: 'test-experimentId', name: 'Test-experimentName', variations: [{ id: 'test-id-original', name: 'Original', weight: 10000 }, { id: 'test-id-variation-b', name: 'Variation B', weight: 0 }] }], 'active': { 'Test-experimentName': 'Variation B' } }); props = { name: 'Variation B', experiment: reduxAbTest.getIn(['experiments', 0]), children: 'Test-children', reduxAbTest: reduxAbTest }; component = _reactTestRenderer2['default'].create(_react2['default'].createElement(_variation.Variation, props)); tree = component.toJSON(); }); it('exists', function () { expect(component).not.toBeUndefined; }); it('has the correct props', function () { expect(tree).toMatchSnapshot(); expect(tree.props['data-experiment-id']).toEqual('test-experimentId'); expect(tree.props['data-experiment-name']).toEqual('Test-experimentName'); expect(tree.props['data-variation-id']).toEqual('test-id-variation-b'); expect(tree.props['data-variation-name']).toEqual('Variation B'); }); it('has the correct text', function () { expect(tree).toMatchSnapshot(); expect(tree.children).toEqual(['Test-children']); }); it('has the correct tagName', function () { expect(tree).toMatchSnapshot(); expect(tree.type).toEqual('span'); }); it('have the correct data-* props', function () { expect(tree).toMatchSnapshot(); expect(tree.props['data-variation-id']).toEqual('test-id-variation-b'); expect(tree.props['data-variation-name']).toEqual('Variation B'); expect(tree.props['data-experiment-id']).toEqual('test-experimentId'); expect(tree.props['data-experiment-name']).toEqual('Test-experimentName'); }); it('adds the props to the children component', function () { props = (0, _extends3['default'])({}, props, { children: _react2['default'].createElement( 'div', { id: 'test-id' }, 'Test-children' ) }); component = _reactTestRenderer2['default'].create(_react2['default'].createElement(_variation.Variation, props)); tree = component.toJSON(); expect(tree).toMatchSnapshot(); expect(tree.type).toEqual('div'); expect(tree.props['id']).toEqual('test-id'); expect(tree.props['data-variation-id']).toEqual('test-id-variation-b'); expect(tree.props['data-variation-name']).toEqual('Variation B'); expect(tree.props['data-experiment-id']).toEqual('test-experimentId'); expect(tree.props['data-experiment-name']).toEqual('Test-experimentName'); expect(tree.children).toEqual(['Test-children']); }); }); // eslint-disable-line no-unused-vars