Skip to content

Instantly share code, notes, and snippets.

@tanner-west
Created April 27, 2022 20:49
Show Gist options
  • Save tanner-west/5a3d1ae3737adf87fbd5add3da01120e to your computer and use it in GitHub Desktop.
Save tanner-west/5a3d1ae3737adf87fbd5add3da01120e to your computer and use it in GitHub Desktop.
import React from 'react';
import Enzyme, {shallow} from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
import Name from './Name';
Enzyme.configure({adapter: new Adapter()});
describe('<Name />', () => {
let wrapper: any;
const createWrapper = () => {
wrapper = shallow(<Name />);
};
beforeEach(() => createWrapper());
it("should render 'get started' message", () => {
const messageWrapper = wrapper.findWhere(
(n: any) => n.text() === 'Please type your name to get started',
);
expect(messageWrapper).toHaveLength(1);
});
it("should render 'Your name is: Ray Bradbury'", () => {
const nameInput = wrapper.findWhere(
(node: any) => node.prop('testID') === 'name-input',
);
nameInput.props().onChangeText('Ray Bradbury');
const nameWrapper = wrapper.findWhere(
(n: any) => n.text() === 'Your name is: Ray Bradbury',
);
expect(nameWrapper).toHaveLength(1);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment