0

I am working on reactjs 5.X version. I am writing UT with enzyme. Below is my reusable component with prop arguments. Not able to find the div tags inside of the const component.Can you help me how to get the div tags using classname or using find function to get div tags.

 import React from 'react';
    import styles from './democheck.css';
    const democheck = ({ input, cb,
      required, testCheckbox, checked, label, meta: { error } }) => (
        <div id="hierrdivid" className={styles.testDivColumn}>
          <div className={styles.testDiv}>
            <br />
            <span className={styles.testLabel}>
              {label}
            </span>
            {required && <span className={styles.error}>
              *
            </span>}
            <input
              {...input}
              name={`form-field-${input.name}`}
              checked={checked}
              id={input.name}
              className={testCheckbox ? styles.testCheckboxError :
                styles.testCheckbox}
              type="checkbox"
              onChange={() => {
                if (cb) {
                  cb(document.getElementById(input.name).checked);
                }
              }}
            />
          </div>
          <div className={styles.testerrorDiv}>
            {testCheckbox &&
              <div className={styles.testerrorLabel}>
                {label} {error}
              </div>}
          </div>
        </div>
      );

    democheck.propTypes = {
      input: React.PropTypes.objectOf(React.PropTypes.oneOfType([
        React.PropTypes.string,
        React.PropTypes.func
      ])),
      cb: React.PropTypes.func,
      label: React.PropTypes.string,
      meta: React.PropTypes.shape({}),`enter code here`
      required: React.PropTypes.bool,
      checked: React.PropTypes.bool,`enter code here`
      testCheckbox: React.PropTypes.bool
    };
Saranya
  • 1
  • 1
  • PFB my test.js file..My wrapper doesn't contain any div tags. describe(‘democheck />', () => { const minprops = { input: [], cb: () => {}, required: true, hierarchyCheckbox: true, checked: true, label: 'Hi', meta: 0, }; it('Render header div', () => { const wrapper =shallow(); console.log(wrapper.html()) expect(wrapper.find('#hierrdivid').length).to.equal(1); }); }); – Saranya Dec 08 '17 at 11:18
  • output of my test.js file is below: and also not finding the div tag with its id, as wrapper doesn't have any div elements.Kindly help me out to get it resolved. – Saranya Dec 08 '17 at 11:18
  • i am not able to attach in one file that's why i splitted and added.. If possible pls check and provide me the solution..it will be helpful. – Saranya Dec 08 '17 at 13:23
  • Hi Team, can anyone help me out to proceed further on my question?? – Saranya Dec 18 '17 at 06:07

0 Answers0