This commit is contained in:
Rico Sta. Cruz 2017-03-14 13:41:29 +08:00
parent d847b1b31e
commit bf3547d2ec
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
2 changed files with 134 additions and 0 deletions

View File

@ -63,6 +63,20 @@ article:tag
<link rel="icon" type="image/png" href="/assets/favicon.png">
```
### Web app
```html
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black"> <!-- black | black-translucent | default -->
```
### Apple-only
```html
<meta name="format-detection" content="telephone=no">
```
### Reference
* https://dev.twitter.com/docs/cards

120
jest.md Normal file
View File

@ -0,0 +1,120 @@
---
title: Jest
category: JavaScript libraries
---
## Testing
```js
beforeEach(() => { ... })
afterEach(() => { ... })
beforeAll(() => { ... })
afterAll(() => { ... })
describe('My work', () => {
test('works', () => {
expect(2).toEqual(2)
})
test('works asynchonously', () => {
return new Promise((resolve, reject) => { ... })
})
test('works asynchonously', async () => {
const hello = await foo()
...
})
})
```
## Expect
```js
expect(value)
.not
.toBe(value)
.toEqual(value)
// Snapshots
.toMatchSnapshot()
// Errors
.toThrow(error)
.toThrowErrorMatchingSnapshot()
// Booleans
.toBeFalsy()
.toBeNull()
.toBeTruthy()
.toBeUndefined()
.toBeDefined()
// Numbers
.toBeCloseTo(number, numDigits)
.toBeGreaterThan(number)
.toBeGreaterThanOrEqual(number)
.toBeLessThan(number)
.toBeLessThanOrEqual(number)
// Objects
.toBeInstanceOf(Class)
.toMatchObject(object)
.toHaveProperty(keyPath, value)
// Arrays
.toContain(item)
.toContainEqual(item)
.toHaveLength(number)
// String
.toMatch(regexpOrString)
```
```js
expect.extend(matchers)
expect.any(constructor)
expect.addSnapshotSerializer(serializer)
expect.assertions(1)
```
## Snapshots
```
const tree = renderer.create(
<Link page="http://www.facebook.com">Facebook</Link>
).toJSON()
// First run creates a snapshot; subsequent runs match it
expect(tree).toMatchSnapshot()
// To update snapshots: jest --updateSnapshot
```
## Mocks
```js
const fn = jest.fn()
const fn = jest.fn(n => n * n)
```
```js
expect(fn)
// Functions
.toHaveBeenCalled()
.toHaveBeenCalledTimes(number)
.toHaveBeenCalledWith(arg1, arg2, ...)
.toHaveBeenLastCalledWith(arg1, arg2, ...)
.toHaveBeenCalledWith(expect.anything())
.toHaveBeenCalledWith(expect.any(constructor))
.toHaveBeenCalledWith(expect.arrayContaining([ values ]))
.toHaveBeenCalledWith(expect.objectContaining({ props }))
.toHaveBeenCalledWith(expect.stringContaining(string))
.toHaveBeenCalledWith(expect.stringMatching(regexp))
```
## References
Based on Jest v19. <http://facebook.github.io/jest/>