Skip to content

Commit 5a9f620

Browse files
author
Sergio Daniel Xalambrí
committed
[update] remove ES6 usage in module and test
1 parent 1762e8a commit 5a9f620

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function middlewareFactory(errorHandler) {
2+
return function middlewareStore(store) {
3+
return function middlewareNext(next) {
4+
return function middlewareAction(action) {
5+
try {
6+
return next(action);
7+
} catch (error) {
8+
errorHandler(error, store.getState);
9+
return error;
10+
}
11+
};
12+
};
13+
};
14+
}
15+
16+
module.exports = middlewareFactory;

lib/index.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/index.js renamed to test.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import test from 'tape';
2-
3-
import middleware from '../build/index.js';
1+
const test = require('tape');
2+
const middleware = require('./index.js');
43

54
const mockedMiddlewareAPI = {
6-
getState() {
5+
getState: function getState() {
76
return 'test';
87
},
98
};
9+
1010
const baseError = new Error('There was an error.');
1111

12-
test('Catch middleware - error case', t => {
13-
const mockedNext = () => {
12+
function errorCase(t) {
13+
function mockedNext() {
1414
throw baseError;
15-
};
15+
}
1616

1717
t.plan(3);
1818

@@ -33,10 +33,10 @@ test('Catch middleware - error case', t => {
3333
error.message === baseError.message,
3434
'it should return the expected error message'
3535
);
36-
});
36+
}
3737

38-
test('Catch middleware - success case', t => {
39-
const mockedNext = action => action;
38+
function successCase(t) {
39+
function mockedNext(action) { return action; }
4040

4141
t.plan(1);
4242

@@ -49,4 +49,7 @@ test('Catch middleware - success case', t => {
4949
'TEST_ACTION',
5050
'it should be the passed action'
5151
);
52-
});
52+
}
53+
54+
test('Catch middleware - error case', errorCase);
55+
test('Catch middleware - success case', successCase);

0 commit comments

Comments
 (0)