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
    };
4
  • 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(<democheck {…minprops} />); console.log(wrapper.html()) expect(wrapper.find('#hierrdivid').length).to.equal(1); }); }); Commented Dec 8, 2017 at 11:18
  • output of my test.js file is below: <democheck label="test1" required=""></democheck> 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. Commented Dec 8, 2017 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. Commented Dec 8, 2017 at 13:23
  • Hi Team, can anyone help me out to proceed further on my question?? Commented Dec 18, 2017 at 6:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.