Skip to content

Instantly share code, notes, and snippets.

@thomashagstrom
Created January 13, 2019 12:30
Show Gist options
  • Save thomashagstrom/eeb14ee5883013ee69f2b5404b44d888 to your computer and use it in GitHub Desktop.
Save thomashagstrom/eeb14ee5883013ee69f2b5404b44d888 to your computer and use it in GitHub Desktop.
Read React state in Jest test
import React from 'react';
import TestRenderer from 'react-test-renderer';
import CognitoLogin from './CognitoLogin';
import _ from 'lodash';
it('When no `code` or `email` `onSavePress` should set `message` to `Need code and user e-mail`', async (done) => {
// Arrange
const wrapper = TestRenderer.create(<CognitoLogin />);
const child = wrapper.root.findByProps({
testID: 'ForgotForm',
});
// Act
await child.props.onSubmit();
// Assert
const result = _.get(wrapper, ['root', 'instance', 'state', 'message']);
expect(result).toBe('Please enter username');
done();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment