B
B
bpGusar2018-10-16 16:52:53
JavaScript
bpGusar, 2018-10-16 16:52:53

How to cover a piece of code with if with tests?

export class Countries extends React.Component<Props, State> {
  private countriesList: React.RefObject<HTMLDivElement> = React.createRef<
    HTMLDivElement
  >();

  public componentDidMount(): void {
    setTimeout(this.whenCDM, 1);
  }


  public render(): React.ReactNode {
    return (
      <div ref={this.countriesList}>
      </div>
    );
  }

  private whenCDM = (): any => {
    if (this.countriesList.current) {
      this.whenComponentDidMount(
        this.countriesList.current.getBoundingClientRect().top
      );
    }
  };
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Laud, 2018-10-16
@kshshe

Make tests for which all conditions will be fulfilled in all cases.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question