The library for web and native user interfaces.
Make ReactIdentity-test less fragile with respect to root IDs.
CommitSyncScript committed
Jun 4, 2013 at 12:52 UTC
bae6100ae8528fcbc7e6085e4c1d6759824fcb36
1 file changed
+19
-16
src/core/__tests__/ReactIdentity-test.js
+19
-16
@@ -18,6 +18,15 @@ describe('ReactIdentity', function() {
18
reactComponentExpect = require('reactComponentExpect');
19
});
20
21
+ var idExp = /^\.reactRoot\[\d+\](.*)$/;
22
+ function checkId(child, expectedId) {
23
+ var actual = idExp.exec(child.id);
24
+ var expected = idExp.exec(expectedId);
25
+ expect(actual).toBeTruthy();
26
+ expect(expected).toBeTruthy();
27
+ expect(actual[1]).toEqual(expected[1]);
28
+ }
29
+
30
it('should allow keyed objects to express identity', function() {
31
var instance =
32
<div>
@@ -30,8 +39,8 @@ describe('ReactIdentity', function() {
39
React.renderComponent(instance, document.createElement('div'));
40
var node = instance.getDOMNode();
41
reactComponentExpect(instance).toBeDOMComponentWithChildCount(2);
33
- expect(node.childNodes[0].id).toEqual('.reactRoot[0].:0:first');
34
- expect(node.childNodes[1].id).toEqual('.reactRoot[0].:0:second');
42
+ checkId(node.childNodes[0], '.reactRoot[0].:0:first');
43
+ checkId(node.childNodes[1], '.reactRoot[0].:0:second');
44
});
45
46
it('should allow key property to express identity', function() {
@@ -44,8 +53,8 @@ describe('ReactIdentity', function() {
53
React.renderComponent(instance, document.createElement('div'));
54
var node = instance.getDOMNode();
55
reactComponentExpect(instance).toBeDOMComponentWithChildCount(2);
47
- expect(node.childNodes[0].id).toEqual('.reactRoot[0].:apple');
48
- expect(node.childNodes[1].id).toEqual('.reactRoot[0].:banana');
56
+ checkId(node.childNodes[0], '.reactRoot[0].:apple');
57
+ checkId(node.childNodes[1], '.reactRoot[0].:banana');
58
});
59
60
it('should use instance identity', function() {
@@ -66,18 +75,12 @@ describe('ReactIdentity', function() {
75
React.renderComponent(instance, document.createElement('div'));
76
var node = instance.getDOMNode();
77
reactComponentExpect(instance).toBeDOMComponentWithChildCount(3);
69
- expect(node.childNodes[0].id)
70
- .toEqual('.reactRoot[0].:wrap1');
71
- expect(node.childNodes[0].firstChild.id)
72
- .toEqual('.reactRoot[0].:wrap1.:squirrel');
73
- expect(node.childNodes[1].id)
74
- .toEqual('.reactRoot[0].:wrap2');
75
- expect(node.childNodes[1].firstChild.id)
76
- .toEqual('.reactRoot[0].:wrap2.:bunny');
77
- expect(node.childNodes[2].id)
78
- .toEqual('.reactRoot[0].:2');
79
- expect(node.childNodes[2].firstChild.id)
80
- .toEqual('.reactRoot[0].:2.:chipmunk');
78
+ checkId(node.childNodes[0], '.reactRoot[0].:wrap1');
79
+ checkId(node.childNodes[0].firstChild, '.reactRoot[0].:wrap1.:squirrel');
80
+ checkId(node.childNodes[1], '.reactRoot[0].:wrap2');
81
+ checkId(node.childNodes[1].firstChild, '.reactRoot[0].:wrap2.:bunny');
82
+ checkId(node.childNodes[2], '.reactRoot[0].:2');
83
+ checkId(node.childNodes[2].firstChild, '.reactRoot[0].:2.:chipmunk');
84
});
85
86
it('should let restructured components retain their uniqueness', function() {