This repository has been archived by the owner on Nov 3, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update babel.transforms to ignore global config files * write some tests for MDXRenderer
- Loading branch information
1 parent
1467eaa
commit 3a93d01
Showing
8 changed files
with
175 additions
and
8 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
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,7 @@ | ||
module.exports = { | ||
env: { | ||
test: { | ||
presets: [["@babel/preset-env"], ["@babel/preset-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
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
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,67 @@ | ||
import React from "react"; | ||
import TestRenderer from "react-test-renderer"; | ||
|
||
import MDXRenderer from "./mdx-renderer"; | ||
|
||
describe("mdx-renderer", () => { | ||
test("fails if there is no content (function body is empty)", () => { | ||
/** | ||
* spyOn is used to silence the following console warning in this test | ||
``` | ||
console.error node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6884 | ||
The above error occurred in one of your React components: | ||
in Unknown (created by Context.Consumer) | ||
in Unknown (created by Context.Consumer) | ||
in Unknown | ||
Consider adding an error boundary to your tree to customize error handling behavior. | ||
Visit https://fb.me/react-error-boundaries to learn more about error boundaries. | ||
``` | ||
*/ | ||
const spy = jest.spyOn(console, "error").mockImplementation(() => {}); | ||
expect(() => TestRenderer.create(<MDXRenderer />)).toThrow(TypeError); | ||
spy.mockRestore(); | ||
}); | ||
|
||
test("renders content if function body is passed in", () => { | ||
const result = TestRenderer.create( | ||
<MDXRenderer>{`return () => 2`}</MDXRenderer> | ||
); | ||
expect(result.toJSON()).toEqual("2"); | ||
}); | ||
|
||
test("fails to render React elements without scope", () => { | ||
/** | ||
* spyOn is used to silence the following console warning in this test | ||
``` | ||
console.error node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6884 | ||
The above error occurred in one of your React components: | ||
in Unknown (created by Context.Consumer) | ||
in Unknown (created by Context.Consumer) | ||
in Unknown | ||
Consider adding an error boundary to your tree to customize error handling behavior. | ||
Visit https://fb.me/react-error-boundaries to learn more about error boundaries. | ||
``` | ||
*/ | ||
const spy = jest.spyOn(console, "error").mockImplementation(() => {}); | ||
expect(() => { | ||
TestRenderer.create( | ||
<MDXRenderer>{`return () => React.createElement('div')`}</MDXRenderer> | ||
); | ||
}).toThrow(ReferenceError); | ||
spy.mockRestore(); | ||
}); | ||
|
||
test("renders React elements when scope is provided", () => { | ||
const result = TestRenderer.create( | ||
<MDXRenderer | ||
scope={{ React: React }} | ||
>{`return () => React.createElement('div')`}</MDXRenderer> | ||
); | ||
|
||
expect(result.toJSON()).toEqual({ type: "div", props: {}, children: null }); | ||
}); | ||
}); |
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