diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-04-20 15:41:42 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-04-20 15:41:42 -0400 |
| commit | 50c68a28bf877ec24bfa5c18bdb63b30477c407e (patch) | |
| tree | 10550716ff150e2adf69f25b6b340fb563770427 /frontend/__tests__/SingleItem.test.js | |
| parent | 426aba70f5addfd3c6c1a972ced18395683feae9 (diff) | |
Single Item Test
Diffstat (limited to 'frontend/__tests__/SingleItem.test.js')
| -rw-r--r-- | frontend/__tests__/SingleItem.test.js | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/frontend/__tests__/SingleItem.test.js b/frontend/__tests__/SingleItem.test.js index ade9727..8625e80 100644 --- a/frontend/__tests__/SingleItem.test.js +++ b/frontend/__tests__/SingleItem.test.js @@ -3,19 +3,63 @@ import { mount } from 'enzyme'; import wait from 'waait'; import toJSON from 'enzyme-to-json'; import SingleItem from '../components/SingleItem'; -import mountOptions from './mockMang'; +import { MockedProvider } from 'react-apollo/test-utils'; +import { SINGLE_ITEM_QUERY } from '../queries/queries'; +import { fakeItem } from './mockMang'; + +const data = { + items: [fakeItem()], +}; describe('<SingleItem/>', () => { it('Renders with Proper Data', async () => { - const wrapper = mount(<SingleItem id="123" />, mountOptions); - await wait(); - wrapper.update(); + const mocks = [ + { + request: { query: SINGLE_ITEM_QUERY, variables: { id: '123' } }, + delay: 50, + result: { data }, + }, + ]; + const wrapper = mount( + <MockedProvider mocks={mocks}> + <SingleItem id="123" /> + </MockedProvider> + ); + // Check for loading state + expect(wrapper.text()).toContain('Loading...'); + // wait for response and refresh + await wait(55); + wrapper.update(); + // Grab the peice we wnat const Item = wrapper.find('[data-test="SingleItem"]'); + // snapshot it! expect(toJSON(Item)).toMatchSnapshot(); }); it('Errors with a not found Item', async () => { - expect('wes').toBe('able to replicate an error'); + const mocks = [ + { + request: { query: SINGLE_ITEM_QUERY, variables: { id: '123' } }, + delay: 50, + // we can return data and an error + result: { data, errors: [{ message: 'Item not found!' }] }, + // or just an error! + // error: new Error('offline!'), + }, + ]; + const wrapper = mount( + <MockedProvider mocks={mocks}> + <SingleItem id="123" /> + </MockedProvider> + ); + + // wait for response + await wait(55); + wrapper.update(); + + const Item = wrapper.find('[data-test="graphql-error"]'); + console.log(Item.debug()); + expect(toJSON(Item)).toMatchSnapshot(); }); }); |
