@samitouri / QOS-React / commits / d61da93878

test(accumulate): add test suite for accumulate function (#15159)

* refactor(typo): remove typo 'be' * test(accumulate): add test suite for accumulate function

Jeffrey Berry committed Apr 25, 2019 at 04:12 UTC d61da93878159d300f8b199cf01d240dd4bf429a
2 files changed +50 -1
packages/events/__tests__/accumulate-test.internal.js new
+49
@@ -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
+1 -1
@@ -22,7 +22,7 @@ function accumulate<T>(
22 ): T | Array<T> {
23 invariant(
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 );
27
28 if (current == null) {