Skip to content

Commit bfe6ad2

Browse files
committed
docs(app): jsdoc integrated
1 parent 8fed7b5 commit bfe6ad2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+14367
-6
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// eslint-disable-next-line
2+
export default from '@react-native-async-storage/async-storage/jest/async-storage-mock'
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Test helper to test async functions to throw
3+
* expected errors
4+
* @param fn
5+
* @param message
6+
* @returns {Promise<void>}
7+
*/
8+
export const expectThrowAsync = async ({ fn, message }) => {
9+
let catched = false
10+
try {
11+
await fn()
12+
}
13+
catch (e) {
14+
expect(e.message).toEqual(message)
15+
catched = true
16+
}
17+
finally {
18+
expect(catched).toEqual(true)
19+
}
20+
}

app/__testHelpers__/mockCollection.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { createCollection } from '../lib/infrastructure/createCollection'
2+
3+
const map = new Map()
4+
5+
export const mockCollection = (context) => {
6+
if (!map.has(context.name)) {
7+
map.set(context.name, createCollection({
8+
name: context.name,
9+
isLocal: true
10+
}))
11+
}
12+
const collection = map.get(context.name)
13+
context.collection = () => collection
14+
return context
15+
}
16+
17+
export const resetCollection = context => context.collection().remove({})
18+
19+
export const restoreCollection = context => {
20+
map.delete(context.name)
21+
context.collection = () => {
22+
throw new Error('is not initialized')
23+
}
24+
}

app/__testHelpers__/simpleRandom.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const simpleRandom = (size = 6) => [...Array(size)]
2+
.map(() => Math.floor(Math.random() * 16).toString(16))
3+
.join('')

app/__testHelpers__/stub.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import sinon from 'sinon'
2+
3+
const stubs = new Map()
4+
5+
export const stub = (target, name, handler) => {
6+
if (stubs.get(target)) {
7+
throw new Error(`already stubbed: ${name}`)
8+
}
9+
const stubbedTarget = sinon.stub(target, name)
10+
if (typeof handler === 'function') {
11+
stubbedTarget.callsFake(handler)
12+
}
13+
else {
14+
stubbedTarget.value(handler)
15+
}
16+
stubs.set(stubbedTarget, name)
17+
}
18+
19+
export const restore = (target, name) => {
20+
if (!target[name] || !target[name].restore) {
21+
throw new Error(`not stubbed: ${name}`)
22+
}
23+
target[name].restore()
24+
stubs.delete(target)
25+
}
26+
27+
export const overrideStub = (target, name, handler) => {
28+
restore(target, name)
29+
stub(target, name, handler)
30+
}
31+
32+
export const restoreAll = () => {
33+
stubs.forEach((name, target) => {
34+
stubs.delete(target)
35+
target.restore()
36+
})
37+
}

app/jsdoc.conf.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"tags": {
3+
"allowUnknownTags": true,
4+
"dictionaries": ["jsdoc", "closure"]
5+
},
6+
"source": {
7+
"include": ["."],
8+
"exclude": [
9+
".expo",
10+
".expo-shared",
11+
"__mocks__",
12+
"__tests__",
13+
"node_modules"
14+
],
15+
"includePattern": ".+\\.js(doc|x)?$",
16+
"excludePattern": "(^|\\/|\\\\)_"
17+
},
18+
"plugins": [
19+
"plugins/markdown"
20+
],
21+
"templates": {
22+
"better-docs": {
23+
"name": "React components"
24+
}
25+
},
26+
"opts": {
27+
"destination": "../docs/api/app",
28+
"recurse": true,
29+
"readme": "../README.md"
30+
}
31+
}

0 commit comments

Comments
 (0)