Skip to content

Commit 06bf78b

Browse files
zhuangyatimche
authored andcommitted
add test cases (#306)
1 parent 796368c commit 06bf78b

8 files changed

+954
-16
lines changed

src/handleActions.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import isMap from './utils/isMap';
55
import ownKeys from './utils/ownKeys';
66
import flattenReducerMap from './utils/flattenReducerMap';
77
import handleAction from './handleAction';
8-
9-
function get(key, x) {
10-
return isMap(x) ? x.get(key) : x[key];
11-
}
8+
import get from './utils/get';
129

1310
export default function handleActions(handlers, defaultState, options = {}) {
1411
invariant(

src/utils/camelCase.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import camelCase from 'to-camel-case';
33
const namespacer = '/';
44

55
export default type =>
6-
type.indexOf(namespacer) === -1
7-
? camelCase(type)
8-
: type
6+
type.includes(namespacer)
7+
? type
98
.split(namespacer)
10-
.map(part => camelCase(part))
11-
.join(namespacer);
9+
.map(camelCase)
10+
.join(namespacer)
11+
: camelCase(type);

src/utils/flattenWhenNode.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { DEFAULT_NAMESPACE, ACTION_TYPE_DELIMITER } from '../constants';
2-
import isMap from './isMap';
32
import ownKeys from './ownKeys';
4-
5-
function get(key, x) {
6-
return isMap(x) ? x.get(key) : x[key];
7-
}
3+
import get from './get';
84

95
export default predicate =>
106
function flatten(

src/utils/get.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import isMap from './isMap';
2+
3+
export default function get(key, x) {
4+
return isMap(x) ? x.get(key) : x[key];
5+
}

src/utils/unflattenActionCreators.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export default function unflattenActionCreators(
88
) {
99
function unflatten(
1010
flatActionType,
11-
partialNestedActionCreators = {},
12-
partialFlatActionTypePath = []
11+
partialNestedActionCreators,
12+
partialFlatActionTypePath
1313
) {
1414
const nextNamespace = camelCase(partialFlatActionTypePath.shift());
1515
if (isEmpty(partialFlatActionTypePath)) {

test/combineActions.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,9 @@ test('returns a stringifiable object', () => {
3131
'ACTION_1||ACTION_2||ACTION_3'
3232
);
3333
});
34+
35+
test('should throw error if actions is empty', () => {
36+
expect(() => combineActions()).toThrow(
37+
'Expected action types to be strings, symbols, or action creators'
38+
);
39+
});

test/get.test.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import get from '../src/utils/get';
2+
3+
test('get util helper', () => {
4+
const map = new Map([['foo', 'bar']]);
5+
const obj = { foo: 'baz' };
6+
7+
expect(get('foo', map)).toBe('bar');
8+
expect(get('foo', obj)).toBe('baz');
9+
});

yarn.lock

+925
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)