Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Created March 18, 2019 23:42
Show Gist options
  • Save ajcrites/837ed043550d28c9b7e0051ddd06dfc7 to your computer and use it in GitHub Desktop.
Save ajcrites/837ed043550d28c9b7e0051ddd06dfc7 to your computer and use it in GitHub Desktop.
import React from 'react';
import { render, fireEvent, cleanup } from 'react-testing-library';
import { ColorToolContext } from '~/ColorToolContext';
import { updateHex } from '~/colorReducer';
import { HexInput } from '../HexInput';
describe('HexInput component', () => {
test('dispatch updated hex value when input changes', () => {
const testHex = '#abcef';
const state = {
hex: '',
rgba: [0, 0, 0, 0],
dispatch: jest.fn(),
};
const { container } = render((
<ColorToolContext.Provider value={state}>
<HexInput />
</ColorToolContext.Provider>
));
const input = container.querySelector('input');
fireEvent.change(input, { target: { value: testHex } });
expect(state.dispatch).toHaveBeenCalledWith(updateHex(testHex));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment