All files / helpers shadowDOM.spec.js

100% Statements 22/22
100% Branches 2/2
100% Functions 4/4
100% Lines 22/22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 431x 1x 1x   1x   1x   1x           2x 2x 2x       2x 1x   1x         1x 1x 1x 1x 1x 1x     1x 1x 1x 1x      
import React from 'react';
import sinon from 'sinon';
import { shallow, mount } from 'enzyme';
 
import shadowDOM from './shadowDOM';
 
import styled from 'styled-components'
 
const MyDiv = styled.div`
  box-sizing: border-box;
  position: relative;
`
 
class MyComponent extends React.PureComponent {
  render() {
    return (
      <MyDiv ref={(node) => this.selectNode = node}>Teste</MyDiv>
    )
  }
  componentDidMount() {
    if (!this.props.noGenerateClass) {
      this.props.generatedClassName(this.selectNode.state.generatedClassName);
    } else {
      this.props.generatedClassName('notexistentsclass');
    }
  }
}
 
describe('<shadowDOMHelper />', () => {
  it('should have a style tag with styles', () => {
    const ShadowComp = shadowDOM(MyComponent)
    const wrapper = mount(<ShadowComp />);
    expect(wrapper.html()).to.have.string('<style')
    expect(wrapper.html()).to.have.string('position:relative')
  })
 
  it('should not have any style class', () => {
    const ShadowComp = shadowDOM(MyComponent)
    const wrapper = mount(<ShadowComp noGenerateClass />);
    expect(wrapper.find('.resolved').length).to.equal(1);
  })
});