-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve coverage on tests with babel
TypeScript compiled to ES6 doesn't change much, so we now test ES6 code so that coverage report is a bit more accurate. Added 'babel-jest', 'babel-preset-es2015' and 'babel-preset-react' as dev dependencies as well as a '.babelrc' file so that jest can transpile the ES6 code and report coverage. Added Enzyme as dev dependency to use the shallow renderer so that we can actually test that Link is being used. Updated readme with install instructions
- Loading branch information
Showing
7 changed files
with
741 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["es2015", "react"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ coverage | |
*.js.map | ||
*.test.js | ||
*.log | ||
.babelrc | ||
src/__snapshots__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
const ReactRouterLinkRenderer = require('./ReactRouterLinkRenderer.js').default | ||
const renderNodes = require('simple-commonmark-react').renderNodes | ||
import React from 'react'; | ||
import renderer from 'react-test-renderer'; | ||
import { BrowserRouter as Router, Link } from 'react-router-dom' | ||
import { shallow } from 'enzyme'; | ||
|
||
test('should render links with React Router\'s Link', () => { | ||
const options = { customRenderers: { link: ReactRouterLinkRenderer } } | ||
const markdown = 'Here is a [link](/some/path)' | ||
import ReactRouterLinkRenderer from './ReactRouterLinkRenderer.js' | ||
import { renderNodes } from 'simple-commonmark-react' | ||
|
||
const nodes = renderNodes(markdown, options) | ||
expect(nodes.length).toEqual(1) | ||
const options = { customRenderers: { link: ReactRouterLinkRenderer } } | ||
const markdown = 'Here is a [link](/some/path)' | ||
const nodes = renderNodes(markdown, options) | ||
|
||
const paragraph = nodes[0] | ||
expect(paragraph.props.children.length).toEqual(2) | ||
test('should render markdown correctly', () => { | ||
const component = renderer.create(<Router><div>{ nodes }</div></Router>) | ||
const tree = component.toJSON() | ||
expect(tree).toMatchSnapshot() | ||
}) | ||
|
||
const link = paragraph.props.children[1] | ||
expect(link.props.to).toEqual('/some/path') | ||
expect(link.props.children).toEqual(['link']) | ||
test('should render markdown with React Router\'s Link', () => { | ||
const paragraphWrapper = shallow(nodes[0]) | ||
expect(paragraphWrapper.find(Link).length).toEqual(1) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should render markdown correctly 1`] = ` | ||
<div> | ||
<p | ||
className={undefined} | ||
> | ||
Here is a | ||
<a | ||
className={undefined} | ||
href="/some/path" | ||
onClick={[Function]} | ||
> | ||
link | ||
</a> | ||
</p> | ||
</div> | ||
`; |
Oops, something went wrong.