Component test utils

Component test utils

  • Philosophy
  • Doc
  • Blog

›Shallow

Introduction

  • Documentation
  • Getting Started

Shallow

  • shallow/constructor
  • shallow/html
  • shallow/props
  • shallow/setProps
  • shallow/querySelector
  • shallow/querySelectors
  • shallow/exists
  • shallow/dispatchEvent
  • shallow/unmount

Frameworks

  • api-react
  • api-vuejs
  • api-angular
  • api-vanilla

shallow/setProps

setProps()

  • Arguments:
    • {object} props The new props to send to the component

Example

React

const Component = ({nbPost, nbLikes}) => {
  return (
    <div>
      {nbPost} - {nbLikes}
    </div>
  );
};

const cmp = shallow(<Component nbPost={4} nbLikes={20} />);

expect(cmp.html()).toBe('<div>4 - 20</div>');

cmp.setProps({
  nbPost: 42,
  nbLikes: 65
});

expect(cmp.html()).toBe('<div>42 - 65</div>');
← shallow/propsshallow/querySelector →
  • setProps()
    • Example
Component test utils
Docs
Getting StartedAPI Reference
More
BlogGitHubStar
MIT Copyright © 2020 Florent Berthelot