[web] Add tests for js/components/Header/FilterDocs.js

This commit is contained in:
Matthew Shao 2017-05-23 19:06:57 +08:00
parent 1ca98c83aa
commit 653505e734
3 changed files with 30 additions and 0 deletions

View File

@ -25,6 +25,7 @@
"dependencies": {
"bootstrap": "^3.3.7",
"classnames": "^2.2.5",
"jest-fetch-mock": "^1.1.1",
"lodash": "^4.17.4",
"prop-types": "^15.5.0",
"react": "^15.4.2",

View File

@ -0,0 +1,19 @@
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', () => {
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)
})
})

View File

@ -2888,6 +2888,12 @@ jest-environment-node@^19.0.0:
jest-mock "^19.0.0"
jest-util "^19.0.0"
jest-fetch-mock@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/jest-fetch-mock/-/jest-fetch-mock-1.1.1.tgz#7548b6d0c0c77071e9f8652fcb4f8d537e988d1f"
dependencies:
whatwg-fetch "1.0.0"
jest-file-exists@^19.0.0:
version "19.0.0"
resolved "https://registry.yarnpkg.com/jest-file-exists/-/jest-file-exists-19.0.0.tgz#cca2e587a11ec92e24cfeab3f8a94d657f3fceb8"
@ -5180,6 +5186,10 @@ whatwg-encoding@^1.0.1:
dependencies:
iconv-lite "0.4.13"
whatwg-fetch@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-1.0.0.tgz#01c2ac4df40e236aaa18480e3be74bd5c8eb798e"
whatwg-fetch@>=0.10.0:
version "2.0.2"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.2.tgz#fe294d1d89e36c5be8b3195057f2e4bc74fc980e"