Skip to content

Commit 07b5971

Browse files
committed
step 8 with tests
1 parent b4f83b3 commit 07b5971

File tree

8 files changed

+64
-22
lines changed

8 files changed

+64
-22
lines changed

coderoad.json

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@
427427
"description": "The power of middleware with \"redux-logger\".\n\nExplanation here.",
428428
"tasks": [
429429
{
430-
"description": "import `applyMiddleware` in \"index.js\"",
430+
"description": "import `applyMiddleware` in \"index.js\" from the \"redux\" package. It is a named import.",
431431
"tests": [
432432
"08/01"
433433
],
@@ -439,24 +439,46 @@
439439
"description": "set the second param in createStore to `applyMiddleware()`",
440440
"tests": [
441441
"08/02"
442+
],
443+
"hints": [
444+
"Try this: `createStore(reducers, applyMiddleware());`"
442445
]
443446
},
444447
{
445448
"description": "install \"redux-logger\" using npm",
446449
"tests": [
447450
"08/03"
451+
],
452+
"hints": [
453+
"Try this: `npm install --save-dev redux-logger`"
448454
]
449455
},
450456
{
451-
"description": "create a \"logger\" as the result of `createLogger()`",
457+
"description": "import `createLogger` from the \"redux-logger\" package. It is a default import.",
452458
"tests": [
453459
"08/04"
460+
],
461+
"hints": [
462+
"Try this: `import createLogger from 'redux-logger';`"
454463
]
455464
},
456465
{
457-
"description": "pass \"logger\" into `applyMiddleware()`",
466+
"description": "create a \"logger\" as the result of `createLogger()`",
458467
"tests": [
459468
"08/05"
469+
],
470+
"hints": [
471+
"Note that `logger` should be above `store`.",
472+
"Try this: `const logger = createLogger()`"
473+
]
474+
},
475+
{
476+
"description": "pass \"logger\" into `applyMiddleware()`",
477+
"tests": [
478+
"08/06"
479+
],
480+
"hints": [
481+
"Try this: `applyMiddleware(logger)`"
460482
]
461483
}
462484
],

tutorial/08/01.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ chai.use(spies);
55

66
let spy = chai.spy.on(console, 'log');
77

8-
const indexJs = require('BASE/index.js');
8+
const indexJs = require('BASE/src/index.js');
99

1010
describe('01 applyMiddleware', () => {
1111

tutorial/08/02.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
describe('02 createStore', () => {
22

3-
// it('should call applyMiddleware', () => {
4-
// console.log("createStore", createStore);
5-
// });
3+
it('should call applyMiddleware', () => {
4+
const regex = /^[a-z]+\sstore\s?=.*applyMiddleware\(.+\)/m;
5+
expect(indexJs.__text__.to.match(regex);
6+
});
67

78
});

tutorial/08/03.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe('03 redux-logger')
1+
describe('03 redux-logger', () => {
22

33
it('should be installed. `npm i -D redux-logger`', () => {
44
expect(exists('node_modules/redux-logger')).to.be.true;

tutorial/08/04.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
describe('04 logger', () => {
2-
3-
const logger = indexJs.__get__('logger');
4-
5-
it('doesn\'t exist', () => {
6-
expect(logger).to.not.be.undefined;
7-
});
8-
9-
it('should be set to `createLogger()`', () => {
1+
describe('04 import', () => {
102

3+
it('createLogger', () => {
4+
const createLogger = indexJs.__get__('createLogger');
5+
expect(createLogger).to.not.be.undefined;
6+
expect(typeof createLogger).to.equal('function');
117
});
128

139
});

tutorial/08/05.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
describe('05 applyMiddleware logger', () => {
1+
describe('05 logger', () => {
22

3-
it('', () => {
3+
const logger = indexJs.__get__('logger');
4+
5+
it('doesn\'t exist', () => {
6+
expect(logger).to.not.be.undefined;
7+
});
8+
9+
it('should be set to `createLogger()`', () => {
410

511
});
612

tutorial/08/06.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
describe('06 logger', () => {
2+
3+
it('should be called by applyMiddleware', () => {
4+
const regex = /^[a-z]+\sstore\s?=.+applyMiddleware\(.*logger.*\)/m;
5+
expect(indexJs.__text__).to.match(regex);
6+
});
7+
8+
});

tutorial/08/index.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,29 @@ The power of middleware with "redux-logger".
33

44
Explanation here.
55

6-
+ import `applyMiddleware` in "index.js"
6+
+ import `applyMiddleware` in "index.js" from the "redux" package. It is a named import.
77
@test('08/01')
88
@action(open('src/index.js'))
99

1010
+ set the second param in createStore to `applyMiddleware()`
1111
@test('08/02')
12+
@hint('Try this: `createStore(reducers, applyMiddleware());`')
1213

1314
+ install "redux-logger" using npm
1415
@test('08/03')
16+
@hint('Try this: `npm install --save-dev redux-logger`')
1517

16-
+ create a "logger" as the result of `createLogger()`
18+
+ import `createLogger` from the "redux-logger" package. It is a default import.
1719
@test('08/04')
20+
@hint('Try this: `import createLogger from 'redux-logger';`')
1821

19-
+ pass "logger" into `applyMiddleware()`
22+
+ create a "logger" as the result of `createLogger()`
2023
@test('08/05')
24+
@hint('Note that `logger` should be above `store`.')
25+
@hint('Try this: `const logger = createLogger()`')
26+
27+
+ pass "logger" into `applyMiddleware()`
28+
@test('08/06')
29+
@hint('Try this: `applyMiddleware(logger)`')
2130

2231
@onPageComplete('Look in the console')

0 commit comments

Comments
 (0)