How to use the react-dom/test-utils.scryRenderedComponentsWithType function in react-dom

To help you get started, weโ€™ve selected a few react-dom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mlaursen / react-md / src / js / Sliders / __tests__ / Slider.js View on Github external
it('renders a text field with the correct props when the editable prop is true', () => {
    let slider = renderIntoDocument();
    let texts = scryRenderedComponentsWithType(slider, TextField);
    expect(texts.length).toBe(0);

    slider = renderIntoDocument();
    texts = scryRenderedComponentsWithType(slider, TextField);
    expect(texts.length).toBe(1);

    const [text] = texts;
    expect(text.props.type).toBe('number');
    expect(text.props.value).toBe(slider.state.value);
    expect(text.props.onChange).toBe(slider._handleTextFieldChange);
    expect(text.props.step).toBe(Slider.defaultProps.step);
  });
github mlaursen / react-md / src / js / TextFields / __tests__ / InputField.js View on Github external
it('renders an input tag when the rows prop is undefined', () => {
    const props = {};
    let field = renderIntoDocument();
    let inputs = scryRenderedDOMComponentsWithTag(field, 'input');
    let areas = scryRenderedComponentsWithType(field, TextArea);

    expect(inputs.length).toBe(1);
    expect(areas.length).toBe(0);

    props.rows = 2;
    field = renderIntoDocument();
    inputs = scryRenderedDOMComponentsWithTag(field, 'input');
    areas = scryRenderedComponentsWithType(field, TextArea);

    expect(inputs.length).toBe(0);
    expect(areas.length).toBe(1);
  });
github mlaursen / react-md / src / js / Pickers / __tests__ / DatePickerHeader.js View on Github external
it('displays a picker control for selecting the year and a picker control for selecting the calendar', () => {
    const DateTimeFormat = require('../../utils/DateUtils/DateTimeFormat');

    const props = {
      changeCalendarMode: jest.fn(),
      DateTimeFormat,
      locales: 'en-US',
      calendarTempDate: new Date(2016, 1, 1),
      calendarMode: 'year',
    };

    const header = renderIntoDocument();
    const controls = scryRenderedComponentsWithType(header, PickerControl);
    expect(controls.length).toBe(2);

    const [year, calendar] = controls;
    expect(year.props.onClick).toBe(header._selectYear);
    expect(calendar.props.onClick).toBe(header._selectCalendar);
  });
github mlaursen / react-md / src / js / Cards / __tests__ / CardTitle.js View on Github external
it('renders the CardTitleBlock with the correct props', () => {
    const props = { title: 'Woop', id: 'boop', subtitle: 'noop' };
    const title = renderIntoDocument();
    const blocks = scryRenderedComponentsWithType(title, CardTitleBlock);
    expect(blocks.length).toBe(1);

    const bProps = blocks[0].props;
    expect(bProps.id).toBe(props.id);
    expect(bProps.title).toBe(props.title);
    expect(bProps.subtitle).toBe(props.subtitle);
  });
});
github mlaursen / react-md / src / js / Pickers / __tests__ / YearPicker.js View on Github external
it('renders the number of years from yearsDisplayed', () => {
    const props = {
      calendarTempDate: new Date(2016, 1, 1),
      onCalendarYearClick: jest.fn(),
      yearsDisplayed: 100,
    };

    let yearPicker = renderIntoDocument();
    let years = scryRenderedComponentsWithType(yearPicker, Year);

    expect(years.length).toBe(props.yearsDisplayed);

    props.yearsDisplayed = 5;
    yearPicker = renderIntoDocument();
    years = scryRenderedComponentsWithType(yearPicker, Year);

    expect(years.length).toBe(props.yearsDisplayed);
  });
github nylas-mail-lives / nylas-mail / packages / client-app / spec / n1-spec-runner / react-test-utils-extensions.es6 View on Github external
export function scryRenderedComponentsWithTypeAndProps(root, type, props) {
  if (!root) { throw new Error("Must supply a root to scryRenderedComponentsWithTypeAndProps"); }
  return _.compact(_.map(ReactTestUtils.scryRenderedComponentsWithType(root, type), (el) => {
    if (_.isEqual(_.pick(el.props, Object.keys(props)), props)) {
      return el;
    }
    return false;
  }));
}
github captivationsoftware / react-sticky / test / unit / sticky.js View on Github external
const mountSticky = (component) => {
    this.stickyContainer = mount();
    this.sticky = ReactTestUtils.scryRenderedComponentsWithType(this.stickyContainer, Sticky)[0];
  };
github mlaursen / react-md / src / js / Pickers / __tests__ / DatePicker.js View on Github external
okPrimary: false,
      onOkClick: jest.fn(),
      cancelLabel: 'a',
      cancelPrimary: false,
      onCancelClick: jest.fn(),
      DateTimeFormat,
      locales: 'en-US',
      calendarDate: new Date(),
      calendarTempDate: new Date(),
      calendarMode: 'year',
      changeCalendarMode: jest.fn(),
      onSwipeChange: jest.fn(),
    };

    const picker = renderIntoDocument();
    const calendars = scryRenderedComponentsWithType(picker, DatePickerCalendar);
    const years = scryRenderedComponentsWithType(picker, YearPicker);
    expect(calendars.length).toBe(0);
    expect(years.length).toBe(1);
  });
});
github Sage / carbon / src / components / table / table-header / table-header.spec.js View on Github external
it('does not return an icon', () => {
        const nonSortableHeader = TestUtils.scryRenderedComponentsWithType(instance, TableHeader)[0];
        expect(nonSortableHeader.sortIconHTML).toEqual(null);
      });
github Sage / carbon / src / components / table / table-header / table-header.spec.js View on Github external
style={ { width: '50px' } }
          />
        
      
    );

    instanceSortable = TestUtils.renderIntoDocument(
      
          
        <table>
        
      </table>
    );

    sortableColumn = TestUtils.findRenderedDOMComponentWithTag(instanceSortable, 'th');
    sortableHeader = TestUtils.scryRenderedComponentsWithType(instanceSortable, TableHeader)[0];
  });