Update
This commit is contained in:
parent
d847b1b31e
commit
bf3547d2ec
14
html-meta.md
14
html-meta.md
|
@ -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
|
||||
|
|
|
@ -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/>
|
Loading…
Reference in New Issue