forked from Workiva/react-dart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchild_key_warning_test.dart
121 lines (99 loc) · 3.34 KB
/
child_key_warning_test.dart
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import 'dart:js';
import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';
import 'package:react/react.dart' as react;
import 'package:react/react_client.dart';
import 'package:react/react_test_utils.dart' as react_test_utils;
void main() {
useHtmlConfiguration();
setClientConfiguration();
void render(JsObject reactElement) {
react_test_utils.renderIntoDocument(reactElement);
}
group('Key/children validation', () {
bool consoleWarnCalled;
var consoleWarnMessage;
JsFunction originalConsoleWarn;
setUp(() {
consoleWarnCalled = false;
consoleWarnMessage = null;
originalConsoleWarn = context['console']['warn'];
context['console']['warn'] = new JsFunction.withThis((self, message) {
consoleWarnCalled = true;
consoleWarnMessage = message;
originalConsoleWarn.apply([message], thisArg: self);
});
});
tearDown(() {
context['console']['warn'] = originalConsoleWarn;
});
group('warns when multiple children are passed as a list', () {
test('when rendering DOM components', () {
render(
react.div({}, [
react.span({}),
react.span({}),
react.span({})
])
);
expect(consoleWarnCalled, isTrue, reason: 'should have outputted a warning');
expect(consoleWarnMessage, contains('Each child in an array or iterator should have a unique "key" prop.'));
});
test('when rendering custom Dart components', () {
render(
CustomComponent({}, [
react.span({}),
react.span({}),
react.span({})
])
);
expect(consoleWarnCalled, isTrue, reason: 'should have outputted a warning');
expect(consoleWarnMessage, contains('Each child in an array or iterator should have a unique "key" prop.'));
});
});
group('does not warn when multiple children are passed as variadic args', () {
test('when rendering DOM components', () {
render(
react.div({},
react.span({}),
react.span({}),
react.span({})
)
);
expect(consoleWarnCalled, isFalse, reason: 'should not have outputted a warning');
});
test('when rendering custom Dart components', () {
render(
CustomComponent({},
react.span({}),
react.span({}),
react.span({})
)
);
expect(consoleWarnCalled, isFalse, reason: 'should not have outputted a warning');
});
});
group('does not warn when a single child is passed', () {
test('when rendering DOM components', () {
render(
react.div({},
react.span({})
)
);
expect(consoleWarnCalled, isFalse, reason: 'should not have outputted a warning');
});
test('when rendering custom Dart components', () {
render(
CustomComponent({},
react.span({})
)
);
expect(consoleWarnCalled, isFalse, reason: 'should not have outputted a warning');
});
});
});
}
Function CustomComponent = react.registerComponent(() => new _CustomComponent());
class _CustomComponent extends react.Component {
render() => react.div({}, []);
}