File tree Expand file tree Collapse file tree 2 files changed +50
-1
lines changed Expand file tree Collapse file tree 2 files changed +50
-1
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @emails react-core
8
+ */
9
+
10
+ 'use strict' ;
11
+
12
+ let accumulate ;
13
+
14
+ describe ( 'accumulate' , ( ) => {
15
+ beforeEach ( ( ) => {
16
+ accumulate = require ( 'events/accumulate' ) . default ;
17
+ } ) ;
18
+
19
+ it ( 'throws if the second item is null' , ( ) => {
20
+ expect ( function ( ) {
21
+ accumulate ( [ ] , null ) ;
22
+ } ) . toThrowError (
23
+ 'accumulate(...): Accumulated items must not be null or undefined.' ,
24
+ ) ;
25
+ } ) ;
26
+
27
+ it ( 'return second item if first item is null' , ( ) => {
28
+ const a = [ ] ;
29
+ expect ( accumulate ( null , a ) ) . toBe ( a ) ;
30
+ } ) ;
31
+
32
+ it ( 'return concatenation of items if first item is an array' , ( ) => {
33
+ const a = [ 'hello' ] ;
34
+ const b = 'world' ;
35
+ expect ( accumulate ( a , b ) ) . toEqual ( [ 'hello' , 'world' ] ) ;
36
+ } ) ;
37
+
38
+ it ( 'return concatenation of items if second item is an array' , ( ) => {
39
+ const a = 'hello' ;
40
+ const b = [ 'world' ] ;
41
+ expect ( accumulate ( a , b ) ) . toEqual ( [ 'hello' , 'world' ] ) ;
42
+ } ) ;
43
+
44
+ it ( 'return an array containing both items if neither item is an array' , ( ) => {
45
+ const a = 'hello' ;
46
+ const b = 'world' ;
47
+ expect ( accumulate ( a , b ) ) . toEqual ( [ 'hello' , 'world' ] ) ;
48
+ } ) ;
49
+ } ) ;
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ function accumulate<T>(
22
22
): T | Array< T > {
23
23
invariant (
24
24
next != null ,
25
- 'accumulate(...): Accumulated items must be not be null or undefined.' ,
25
+ 'accumulate(...): Accumulated items must not be null or undefined.' ,
26
26
) ;
27
27
28
28
if ( current == null ) {
You can’t perform that action at this time.
0 commit comments