Skip to content

Commit

Permalink
[test] fix tests related to timings
Browse files Browse the repository at this point in the history
  • Loading branch information
watson committed Jun 8, 2021
1 parent e33aa21 commit 5383f19
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@

jest.useFakeTimers();

import { promisify } from 'util';
import React from 'react';
import { render, mount } from 'enzyme';
import { VisualizationChart } from './visualization_chart';

let renderPromise;

const nextTick = promisify(process.nextTick);

class VisualizationStub {
constructor(el, vis) {
this.el = el;
Expand Down Expand Up @@ -70,6 +73,7 @@ describe('<VisualizationChart/>', () => {

jest.runAllTimers();
await renderPromise;
await nextTick();
expect(renderStart).toHaveBeenCalledTimes(1);
expect(renderComplete).toHaveBeenCalledTimes(1);

Expand All @@ -89,12 +93,14 @@ describe('<VisualizationChart/>', () => {
domNode.addEventListener('renderComplete', renderComplete);
jest.runAllTimers();
await renderPromise;
await nextTick();
expect(renderComplete).toHaveBeenCalledTimes(1);

vis.params.markdown = 'new text';
wrapper.setProps({ vis });
jest.runAllTimers();
await renderPromise;
await nextTick();

expect(wrapper.find('.visChart').text()).toBe('new text');
expect(renderComplete).toHaveBeenCalledTimes(2);
Expand Down

0 comments on commit 5383f19

Please sign in to comment.