-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathenzyme.react.txt
88 lines (71 loc) · 4.19 KB
/
enzyme.react.txt
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
┏━━━━━━━━━━━━┓
┃ ENZYME ┃
┗━━━━━━━━━━━━┛
VERSION ==> #2.7.1
#Requires:
# - ReactDOM, react-addons-test-utils
# - cheerio, if using render()
# - jsdom, if using mount() and not in a browser
GOAL ==> #Test React RELEM
┌────────────┐
│ RENDER │
└────────────┘
SHALLOW VS DEEP ==> #Whether to call sub-components render() methods
ENZYM.shallow(RELEM[,OPT])->ERCOMP#Shallow render RELEM
#OPT:
# - context OBJ
ERCOMP.shallow([OPT])->ERCOMP #Only on shallow-rendered ERCOMP's children
ERCOMP.dive([OPT])->ERCOMP #Same but keep current OPT by default
ENZYME.mount(RELEM[,OPT])->ERCOMP #Deep render RELEM
#OPT:
# - context OBJ
# - childContextTypes OBJ: merged to descendants contextTypes
# - attachTo ELEM:
# - actually mount on DOM element
# - can unmountComponentAtNode() with ERCOMP.detach()
ERCOMP.render()->JC
ENZYME.render(RELEM)->JC #Returns as CHEERIO's JC
┌────────────────┐
│ ASSERTIONS │
└────────────────┘
ERCOMP #Can be:
# - "single": only one root node, i.e. at beginning
# - "multiple": several root nodes, i.e. after find()
ERCOMP.type()->'TAG'|RTYPE #
ERCOMP.instance()->RCOMP #
ERCOMP.getNode()->RELEM #Only on single ERCOMP
ERCOMP.getNodes()->RELEM_ARR #Only on multiple ERCOMP
ERCOMP.getDOMNode()->ELEM #Only on single deep-rendered ERCOMP
ERCOMP.[un]mount() #Simulates unmount|remount
#remount only possible with deep-rendered ERCOMP
ERCOMP.update() #Does RCOMP.forceUpdate()
ERCOMP.state(['VAR']) #Returns STATE[.VAR]
ERCOMP.props()
ERCOMP.prop('VAR') #Returns PROPS[.VAR]
ERCOMP.context(['VAR']) #Returns CONTEXT[.VAR]
ERCOMP.setState|Props|Context(OBJ)#
ERCOMP.key()->STR #Returns RCOMP.key
ERCOMP.name()->STR #Returns displayName|name|'TAG'
ERCOMP.ref('REF')->VAL #Returns RCOMP.refs.REF
#Only on deep-rendered ERCOMP
ERCOMP.simulate('EVENT'[, OBJ]) #Simulates DOM event
#OBJ is merged with event object
ERCOMP.find|filter|hasClass|is|not#Like jQuery but
|children|parents|parent|closest| # - returns ERCOMP2
html|text|get|at|first|last(...) # - SELECTOR can also be RTYPE, RTYPE.displayName or PROPS subset
ERCOMP.childAt(NUM) #Same as ERCOMP.children().at(NUM)
ERCOMP.exists()->BOOL #Whether ERCOMP is empty
ERCOMP.some|every(SELECTOR)->BOOL #
ERCMP.contains(RELEM2[_ARR])->BOOL#Similar to jQuery. Compare content not identity.
ERCOMP.debug() #Beautified html()
ERCOMP.equals(RELEM)->BOOL #Check if RELEM is a subset (comparison of type|props) of ERCOMP
ERCOMP.matchesElement(RELEM)->BOOL#Is recursive: RELEM's descendants list can be a subset of ERCOMP's descendants (matchesElement()) or not (equals())
ERCOMP.containsMatchingElement
(RELEM)->BOOL
ERCOMP.
containsAny|AllMatchingElements
(RELEM_ARR)->BOOL #Same as matchesElement() but only for ERCOMP descendants
ERCOMP.findWhere|filterWhere|
forEach|map|reduce[Right]|
someWhere|everyWhere|tap(...) #Like Lodash
ERCOMP.slice(...) #Like ARR