[web] js/components/Header/FilterDocs.jsx coverage ++

This commit is contained in:
Matthew Shao 2017-05-26 17:23:57 +08:00
parent 653505e734
commit 05d78a8353

View File

@ -1,19 +1,18 @@
import React from 'react'
import renderer from 'react-test-renderer'
import FilterDocs from '../../../components/Header/FilterDocs'
import mockFetch from 'jest-fetch-mock'
global.fetch = mockFetch
describe('FilterDocs Component', () => {
let mockResponse = { json:
jest.fn(() => { return { commands: [['cmd1', 'foo'], ['cmd2', 'bar']]}})
},
promise = Promise.resolve(mockResponse)
global.fetch = jest.fn(r => { return promise })
it('should render correctly', () => {
// fetch successes
fetch.mockResponseOnce(JSON.stringify({commands: [['cmd1', 'foo'], ['cmd2', 'bar']]}), {status: 200})
let filterDocs = renderer.create(<FilterDocs/>),
tree = filterDocs.toJSON()
// [TODO] doc in render() could not be set correctly.
console.log(tree)
let filterDocs = renderer.create(<FilterDocs/>),
tree = filterDocs.toJSON()
it('should render correctly when fetch success', () => {
expect(tree).toMatchSnapshot()
})
})