Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test cases #306

Merged
merged 1 commit into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/handleActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import isMap from './utils/isMap';
import ownKeys from './utils/ownKeys';
import flattenReducerMap from './utils/flattenReducerMap';
import handleAction from './handleAction';

function get(key, x) {
return isMap(x) ? x.get(key) : x[key];
}
import get from './utils/get';

export default function handleActions(handlers, defaultState, options = {}) {
invariant(
Expand Down
10 changes: 5 additions & 5 deletions src/utils/camelCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import camelCase from 'to-camel-case';
const namespacer = '/';

export default type =>
type.indexOf(namespacer) === -1
? camelCase(type)
: type
type.includes(namespacer)
? type
.split(namespacer)
.map(part => camelCase(part))
.join(namespacer);
.map(camelCase)
.join(namespacer)
: camelCase(type);
6 changes: 1 addition & 5 deletions src/utils/flattenWhenNode.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { DEFAULT_NAMESPACE, ACTION_TYPE_DELIMITER } from '../constants';
import isMap from './isMap';
import ownKeys from './ownKeys';

function get(key, x) {
return isMap(x) ? x.get(key) : x[key];
}
import get from './get';

export default predicate =>
function flatten(
Expand Down
5 changes: 5 additions & 0 deletions src/utils/get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import isMap from './isMap';

export default function get(key, x) {
return isMap(x) ? x.get(key) : x[key];
}
4 changes: 2 additions & 2 deletions src/utils/unflattenActionCreators.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export default function unflattenActionCreators(
) {
function unflatten(
flatActionType,
partialNestedActionCreators = {},
partialFlatActionTypePath = []
partialNestedActionCreators,
partialFlatActionTypePath
zhuangya marked this conversation as resolved.
Show resolved Hide resolved
) {
const nextNamespace = camelCase(partialFlatActionTypePath.shift());
if (isEmpty(partialFlatActionTypePath)) {
Expand Down
6 changes: 6 additions & 0 deletions test/combineActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ test('returns a stringifiable object', () => {
'ACTION_1||ACTION_2||ACTION_3'
);
});

test('should throw error if actions is empty', () => {
expect(() => combineActions()).toThrow(
'Expected action types to be strings, symbols, or action creators'
);
});
9 changes: 9 additions & 0 deletions test/get.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import get from '../src/utils/get';

test('get util helper', () => {
const map = new Map([['foo', 'bar']]);
const obj = { foo: 'baz' };

expect(get('foo', map)).toBe('bar');
expect(get('foo', obj)).toBe('baz');
});
925 changes: 925 additions & 0 deletions yarn.lock

Large diffs are not rendered by default.