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/html

html()

This method return the html() of the component in a String.

  • Returns: {string} the markup

Example

with react

const Hello = ({name}) => {
  return <div>Hello World, {name}</div>;
};

const component = shallow(<Hello />, {props: {name: 'test'}});

component.html(); // "<div>Hello World, test</div>"

with angular

import 'core-js/es7/reflect';
import {Component} from '@angular/core';
import {shallow} from 'component-test-utils-angular';

@Component({
  selector: 'component',
  template: '<h1>Hello test world</h1>'
})
class MyComponent {}

const cmp = shallow(MyComponent);
cmp.html(); // "<h1>Hello test world</h1>"
← shallow/constructorshallow/props →
  • html()
    • Example
Component test utils
Docs
Getting StartedAPI Reference
More
BlogGitHubStar
MIT Copyright © 2020 Florent Berthelot