Skip to content

Instantly share code, notes, and snippets.

@oshell
Last active November 17, 2019 22:31

Revisions

  1. oshell revised this gist Nov 17, 2019. 1 changed file with 4 additions and 7 deletions.
    11 changes: 4 additions & 7 deletions App.test.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ import React from 'react';
    import { shallow } from 'enzyme';
    import App from './App';

    it('button click changes color of box', () => {
    it('button click changes color of box', async () => {
    const app = shallow(<App />);
    expect(app.find('.box').length).toEqual(1);
    // cache button element
    @@ -15,9 +15,6 @@ it('button click changes color of box', () => {
    }
    };
    // pass mocked event object
    const promise = button.props().onClick(eventMock);
    promise.then(() => {
    expect(app.find('.box.red').length).toEqual(1);
    });
    });

    await button.props().onClick(eventMock);
    expect(app.find('.box.red').length).toEqual(1);
    });
  2. oshell created this gist Nov 17, 2019.
    23 changes: 23 additions & 0 deletions App.test.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    import React from 'react';
    import { shallow } from 'enzyme';
    import App from './App';

    it('button click changes color of box', () => {
    const app = shallow(<App />);
    expect(app.find('.box').length).toEqual(1);
    // cache button element
    const button = app.find('button').last();
    const eventMock = {
    target: {
    getAttribute: function() {
    return button.props()['data-color']
    }
    }
    };
    // pass mocked event object
    const promise = button.props().onClick(eventMock);
    promise.then(() => {
    expect(app.find('.box.red').length).toEqual(1);
    });
    });