|
| 1 | +import * as React from 'react'; |
| 2 | +import * as Adapter from 'enzyme-adapter-react-16'; |
| 3 | +import * as Enzyme from 'enzyme'; |
| 4 | +const assert = require('assert'); |
| 5 | +import {jsxFactory, h, ReactSource, makeCycleReactComponent} from '../src'; |
| 6 | + |
| 7 | +Enzyme.configure({adapter: new Adapter()}); |
| 8 | + |
| 9 | +const {shallow} = Enzyme; |
| 10 | + |
| 11 | +describe('jsxFactory', function () { |
| 12 | + it('w/ nothing', () => { |
| 13 | + const wrapper = shallow(<h1></h1>); |
| 14 | + |
| 15 | + assert.strictEqual(wrapper.find('h1').length, 1); |
| 16 | + }); |
| 17 | + |
| 18 | + it('w/ text child', () => { |
| 19 | + const wrapper = shallow(<h1>heading 1</h1>); |
| 20 | + |
| 21 | + const h1 = wrapper.find('h1'); |
| 22 | + assert.strictEqual(h1.text(), 'heading 1'); |
| 23 | + }); |
| 24 | + |
| 25 | + it('w/ children array', () => { |
| 26 | + const wrapper = shallow( |
| 27 | + <section> |
| 28 | + <h1>heading 1</h1> |
| 29 | + <h2>heading 2</h2> |
| 30 | + <h3>heading 3</h3> |
| 31 | + </section> |
| 32 | + ); |
| 33 | + |
| 34 | + const section = wrapper.find('section'); |
| 35 | + assert.strictEqual(section.children().length, 3); |
| 36 | + }); |
| 37 | + |
| 38 | + it('w/ props', () => { |
| 39 | + const wrapper = shallow(<section data-foo='bar' />); |
| 40 | + |
| 41 | + assert(wrapper.exists('[data-foo="bar"]')); |
| 42 | + }); |
| 43 | + |
| 44 | + it('w/ props and children', () => { |
| 45 | + const wrapper = shallow( |
| 46 | + <section data-foo="bar"> |
| 47 | + <h1>heading 1</h1> |
| 48 | + <h2>heading 2</h2> |
| 49 | + <h3>heading 3</h3> |
| 50 | + </section> |
| 51 | + ); |
| 52 | + |
| 53 | + const section = wrapper.first(); |
| 54 | + assert.strictEqual(section.length, 1); |
| 55 | + assert(section.exists('[data-foo="bar"]')); |
| 56 | + assert.deepStrictEqual(section.children().length, 3); |
| 57 | + }); |
| 58 | + |
| 59 | + it('w/ className', () => { |
| 60 | + const wrapper = shallow(<section className="foo" />); |
| 61 | + |
| 62 | + assert(wrapper.hasClass('foo')); |
| 63 | + }); |
| 64 | + |
| 65 | + it('renders functional component', () => { |
| 66 | + const Test = () => <h1>Functional</h1>; |
| 67 | + const wrapper = shallow(<Test />); |
| 68 | + |
| 69 | + assert.strictEqual(wrapper.first().type(), 'h1'); |
| 70 | + }); |
| 71 | + |
| 72 | + it('renders class component', () => { |
| 73 | + class Test extends React.Component { |
| 74 | + render() { |
| 75 | + return <h1>Class</h1>; |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + const wrapper = shallow(<Test />); |
| 80 | + |
| 81 | + assert.strictEqual(wrapper.first().type(), 'h1'); |
| 82 | + }); |
| 83 | +}); |
0 commit comments