Skip to content

Commit ad61c40

Browse files
brooksbectonthymikee
authored andcommitted
docs: add website built with Docusaurus (#74)
* Run docusaurus init * Add api.md and remove initial files * Run docusaurus init * Add api.md and remove initial files * Add callstack info and remove extra scripts * Commeent out extra features on home page and Add link to example * Re Arrange Docs Folder * add some adjustments * fix lint * fix lint
1 parent 1673bc0 commit ad61c40

23 files changed

+6671
-8
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "@callstack",
33
"rules": {
4-
"flowtype/no-weak-types": 0
4+
"flowtype/no-weak-types": 0,
5+
"react/no-multi-comp": 0
56
}
67
}

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ As you may have noticed, it's not tied to React Native at all – you can safely
6666

6767
## API / Usage
6868

69-
The [public API](docs/api.md) of `react-native-testing-library` is focused around these essential methods:
69+
The [public API](docs/API.md) of `react-native-testing-library` is focused around these essential methods:
7070

71-
- [`render`](docs/api.md#render) – deeply renders given React element and returns helpers to query the output components.
72-
- [`shallow`](docs/api.md#shallow) – shallowly renders given React component. It doesn't return any helpers to query the output.
73-
- [`fireEvent`](docs/api.md#fireevent) - invokes named event handler on the element.
74-
- [`waitForElement`](docs/api.md#waitforelement) - waits for non-deterministic periods of time until your element appears or times out.
75-
- [`flushMicrotasksQueue`](docs/api.md#flushmicrotasksqueue) - waits for microtasks queue to flush.
71+
- [`render`](docs/API.md#render) – deeply renders given React element and returns helpers to query the output components.
72+
- [`shallow`](docs/API.md#shallow) – shallowly renders given React component. It doesn't return any helpers to query the output.
73+
- [`fireEvent`](docs/API.md#fireevent) - invokes named event handler on the element.
74+
- [`waitForElement`](docs/API.md#waitforelement) - waits for non-deterministic periods of time until your element appears or times out.
75+
- [`flushMicrotasksQueue`](docs/API.md#flushmicrotasksqueue) - waits for microtasks queue to flush.
7676

7777
<!-- badges -->
7878

docs/GettingStarted.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
id: getting-started
3+
title: Getting Started
4+
---
5+
6+
## The problem
7+
8+
You want to write maintainable tests for your React Native components without testing implementation details, but then you're told to use Enzyme, which you learn has no React Native adapter, meaning only shallow rendering is supported. And you want to render deep! But deep rendering may otherwise require jsdom (React Native isn't the web!), while doing deep rendering with `react-test-renderer` is so painful.
9+
10+
You would also like to use the newest React features, but you need to wait for your testing library's abstractions to catch up and it takes a while.
11+
12+
You finally want to approach testing using only best practices, while Enzyme may encourage assertions on implementation details.
13+
14+
## This solution
15+
16+
The `react-native-testing-library` is a lightweight solution for testing your React Native components. It provides light utility functions on top of `react-test-renderer` letting you always be up to date with latest React features and write any component tests you like, be it shallow or deeply rendered ones. But really not any, it prevents you from testing implementation details because we stand this is a very bad practice.
17+
18+
This library is a replacement for [Enzyme](http://airbnb.io/enzyme/).
19+
20+
## Example
21+
22+
```jsx
23+
import { render, fireEvent } from 'react-native-testing-library';
24+
import { QuestionsBoard } from '../QuestionsBoard';
25+
import { Question } from '../Question';
26+
27+
function setAnswer(question, answer) {
28+
fireEvent.changeText(question, answer);
29+
}
30+
31+
test('should verify two questions', () => {
32+
const { getAllByType, getByText } = render(<QuestionsBoard {...props} />);
33+
const allQuestions = getAllByType(Question);
34+
35+
setAnswer(allQuestions[0], 'a1');
36+
setAnswer(allQuestions[1], 'a2');
37+
38+
fireEvent.press(getByText('submit'));
39+
40+
expect(props.verifyQuestions).toBeCalledWith({
41+
'1': { q: 'q1', a: 'a1' },
42+
'2': { q: 'q2', a: 'a2' },
43+
});
44+
});
45+
```
46+
47+
## Installation
48+
49+
Open a Terminal in your project's folder and run:
50+
51+
```sh
52+
yarn add --dev react-native-testing-library
53+
```
54+
55+
This library has a peerDependencies listing for `react-test-renderer` and, of course, `react`. Make sure to install them too!
56+
57+
As you may have noticed, it's not tied to React Native at all – you can safely use it in your React components if you feel like not interacting directly with DOM.

docs/api.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# API / Usage
1+
---
2+
id: api
3+
title: API
4+
---
25

36
This page gathers public API of `react-native-testing-library` along with usage examples.
47

website/.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.DS_Store
2+
3+
node_modules
4+
5+
lib/core/metadata.js
6+
lib/core/MetadataBlog.js
7+
8+
website/translated_docs
9+
website/build/
10+
website/yarn.lock
11+
website/node_modules
12+
website/i18n/*

website/README.md

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
This website was created with [Docusaurus](https://docusaurus.io/).
2+
3+
# What's In This Document
4+
5+
* [Get Started in 5 Minutes](#get-started-in-5-minutes)
6+
* [Directory Structure](#directory-structure)
7+
* [Editing Content](#editing-content)
8+
* [Adding Content](#adding-content)
9+
* [Full Documentation](#full-documentation)
10+
11+
# Get Started in 5 Minutes
12+
13+
1. Make sure all the dependencies for the website are installed:
14+
15+
```sh
16+
# Install dependencies
17+
$ yarn
18+
```
19+
2. Run your dev server:
20+
21+
```sh
22+
# Start the site
23+
$ yarn start
24+
```
25+
26+
## Directory Structure
27+
28+
Your project file structure should look something like this
29+
30+
```
31+
my-docusaurus/
32+
docs/
33+
doc-1.md
34+
doc-2.md
35+
doc-3.md
36+
website/
37+
blog/
38+
2016-3-11-oldest-post.md
39+
2017-10-24-newest-post.md
40+
core/
41+
node_modules/
42+
pages/
43+
static/
44+
css/
45+
img/
46+
package.json
47+
sidebar.json
48+
siteConfig.js
49+
```
50+
51+
# Editing Content
52+
53+
## Editing an existing docs page
54+
55+
Edit docs by navigating to `docs/` and editing the corresponding document:
56+
57+
`docs/doc-to-be-edited.md`
58+
59+
```markdown
60+
---
61+
id: page-needs-edit
62+
title: This Doc Needs To Be Edited
63+
---
64+
65+
Edit me...
66+
```
67+
68+
For more information about docs, click [here](https://docusaurus.io/docs/en/navigation)
69+
70+
## Editing an existing blog post
71+
72+
Edit blog posts by navigating to `website/blog` and editing the corresponding post:
73+
74+
`website/blog/post-to-be-edited.md`
75+
```markdown
76+
---
77+
id: post-needs-edit
78+
title: This Blog Post Needs To Be Edited
79+
---
80+
81+
Edit me...
82+
```
83+
84+
For more information about blog posts, click [here](https://docusaurus.io/docs/en/adding-blog)
85+
86+
# Adding Content
87+
88+
## Adding a new docs page to an existing sidebar
89+
90+
1. Create the doc as a new markdown file in `/docs`, example `docs/newly-created-doc.md`:
91+
92+
```md
93+
---
94+
id: newly-created-doc
95+
title: This Doc Needs To Be Edited
96+
---
97+
98+
My new content here..
99+
```
100+
101+
1. Refer to that doc's ID in an existing sidebar in `website/sidebar.json`:
102+
103+
```javascript
104+
// Add newly-created-doc to the Getting Started category of docs
105+
{
106+
"docs": {
107+
"Getting Started": [
108+
"quick-start",
109+
"newly-created-doc" // new doc here
110+
],
111+
...
112+
},
113+
...
114+
}
115+
```
116+
117+
For more information about adding new docs, click [here](https://docusaurus.io/docs/en/navigation)
118+
119+
## Adding a new blog post
120+
121+
1. Make sure there is a header link to your blog in `website/siteConfig.js`:
122+
123+
`website/siteConfig.js`
124+
```javascript
125+
headerLinks: [
126+
...
127+
{ blog: true, label: 'Blog' },
128+
...
129+
]
130+
```
131+
132+
2. Create the blog post with the format `YYYY-MM-DD-My-Blog-Post-Title.md` in `website/blog`:
133+
134+
`website/blog/2018-05-21-New-Blog-Post.md`
135+
136+
```markdown
137+
---
138+
author: Frank Li
139+
authorURL: https://twitter.com/foobarbaz
140+
authorFBID: 503283835
141+
title: New Blog Post
142+
---
143+
144+
Lorem Ipsum...
145+
```
146+
147+
For more information about blog posts, click [here](https://docusaurus.io/docs/en/adding-blog)
148+
149+
## Adding items to your site's top navigation bar
150+
151+
1. Add links to docs, custom pages or external links by editing the headerLinks field of `website/siteConfig.js`:
152+
153+
`website/siteConfig.js`
154+
```javascript
155+
{
156+
headerLinks: [
157+
...
158+
/* you can add docs */
159+
{ doc: 'my-examples', label: 'Examples' },
160+
/* you can add custom pages */
161+
{ page: 'help', label: 'Help' },
162+
/* you can add external links */
163+
{ href: 'https://github.com/facebook/Docusaurus', label: 'GitHub' },
164+
...
165+
],
166+
...
167+
}
168+
```
169+
170+
For more information about the navigation bar, click [here](https://docusaurus.io/docs/en/navigation)
171+
172+
## Adding custom pages
173+
174+
1. Docusaurus uses React components to build pages. The components are saved as .js files in `website/pages/en`:
175+
1. If you want your page to show up in your navigation header, you will need to update `website/siteConfig.js` to add to the `headerLinks` element:
176+
177+
`website/siteConfig.js`
178+
```javascript
179+
{
180+
headerLinks: [
181+
...
182+
{ page: 'my-new-custom-page', label: 'My New Custom Page' },
183+
...
184+
],
185+
...
186+
}
187+
```
188+
189+
For more information about custom pages, click [here](https://docusaurus.io/docs/en/custom-pages).
190+
191+
# Full Documentation
192+
193+
Full documentation can be found on the [website](https://docusaurus.io/).

0 commit comments

Comments
 (0)