diff options
Diffstat (limited to 'finished-application/frontend/__tests__/SingleItem.test.js')
| -rw-r--r-- | finished-application/frontend/__tests__/SingleItem.test.js | 52 |
1 files changed, 21 insertions, 31 deletions
diff --git a/finished-application/frontend/__tests__/SingleItem.test.js b/finished-application/frontend/__tests__/SingleItem.test.js index aeb8554..2963bde 100644 --- a/finished-application/frontend/__tests__/SingleItem.test.js +++ b/finished-application/frontend/__tests__/SingleItem.test.js @@ -1,26 +1,22 @@ -import React from 'react'; import { mount } from 'enzyme'; -import wait from 'waait'; import toJSON from 'enzyme-to-json'; +import wait from 'waait'; import SingleItem, { SINGLE_ITEM_QUERY } from '../components/SingleItem'; import { MockedProvider } from 'react-apollo/test-utils'; -import { fakeItem, fakeUser } from '../lib/testUtils'; -import { CURRENT_USER_QUERY } from '../components/User'; - -const data = { - items: [fakeItem()], -}; +import { fakeItem } from '../lib/testUtils'; describe('<SingleItem/>', () => { - it('Renders with Proper Data', async () => { + it('renders with proper data', async () => { const mocks = [ { + // when someone makes a request with this query and variable combo request: { query: SINGLE_ITEM_QUERY, variables: { id: '123' } }, - result: { data }, - }, - { - request: { query: CURRENT_USER_QUERY }, - result: { data: { me: fakeUser() } }, + // return this fake data (mocked data) + result: { + data: { + item: fakeItem(), + }, + }, }, ]; const wrapper = mount( @@ -28,27 +24,22 @@ describe('<SingleItem/>', () => { <SingleItem id="123" /> </MockedProvider> ); - // Check for loading state expect(wrapper.text()).toContain('Loading...'); - - // wait for response and refresh - await wait(55); + await wait(); wrapper.update(); - // Grab the piece we want + // console.log(wrapper.debug()); expect(toJSON(wrapper.find('h2'))).toMatchSnapshot(); expect(toJSON(wrapper.find('img'))).toMatchSnapshot(); expect(toJSON(wrapper.find('p'))).toMatchSnapshot(); }); - it('Errors with a not found Item', async () => { + it('Errors with a not found item', async () => { 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!'), + result: { + errors: [{ message: 'Items Not Found!' }], + }, }, ]; const wrapper = mount( @@ -56,12 +47,11 @@ describe('<SingleItem/>', () => { <SingleItem id="123" /> </MockedProvider> ); - - // wait for response - await wait(55); + await wait(); wrapper.update(); - - const Item = wrapper.find('[data-test="graphql-error"]'); - expect(toJSON(Item)).toMatchSnapshot(); + console.log(wrapper.debug()); + const item = wrapper.find('[data-test="graphql-error"]'); + expect(item.text()).toContain('Items Not Found!'); + expect(toJSON(item)).toMatchSnapshot(); }); }); |
