Skip to content

Commit d61da93

Browse files
jberry93cpojer
authored andcommitted
test(accumulate): add test suite for accumulate function (#15159)
* refactor(typo): remove typo 'be' * test(accumulate): add test suite for accumulate function
1 parent a187e9b commit d61da93

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
});

packages/events/accumulate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function accumulate<T>(
2222
): T | Array<T> {
2323
invariant(
2424
next != null,
25-
'accumulate(...): Accumulated items must be not be null or undefined.',
25+
'accumulate(...): Accumulated items must not be null or undefined.',
2626
);
2727

2828
if (current == null) {

0 commit comments

Comments
 (0)