forked from primer/react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
46 lines (40 loc) · 1.55 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import React from 'react'
// 1. uncomment this line and change "SomeComponent"
// import SomeComponent from '../SomeComponent'
import {colors} from '../theme'
import {render, renderStyles} from '../utils/testing'
import {COMMON} from '../constants'
// 2. remove this definition; it's just for eslint
function SomeComponent() {}
// 3. remove the leading "x" from this line to enable the test
describe.skip('SomeComponent', () => {
// if applicable, ensure that this is a "system component"
it('is a system component', () => {
expect(SomeComponent.systemComponent).toBe(true)
})
// ensure that it implements common props
it('implements common system props', () => {
expect(SomeComponent).toImplementSystemProps(COMMON)
})
it('matches the snapshot', () => {
expect(render(<SomeComponent />)).toMatchSnapshot()
})
// this is generally how you test that a prop renders one or more styles
it('renders "x" prop into styles', () => {
// use the .toMatchKeys() to test a subset of the rendered styles
expect(renderStyles(<SomeComponent scheme="green" />)).toMatchKeys({
'background-color': colors.green[5]
})
// or use .toEqual() if:
// * your component shouldn't render any other styles; or
// * you know the other ("base") styles that your component should
// render, and you can spread them into the result
const defaultStyles = {
color: colors.bodytext
}
expect(renderStyles(<SomeComponent scheme="green" />)).toEqual({
...defaultStyles,
'background-color': colors.green[5]
})
})
})