learn-co-curriculum / redux-initial-dispatch Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
In the code snippet:
dispatch({ type: '@@INIT' }) -> { counter: 0 } dispatch({type: 'INCREASE'}) -> { counter: 1 }
Should counter be count?
I was having trouble getting the tests to execute successfully against my own code so on a whim I switched to the solution branch and ran the tests to see if the tests were just broken. While the tests finally executed successfully, the solution branch fails the tests with this logging:
managePets reducer adds the pet when type is ADD_PET and the action has a payload property with the pet:
Error: Expected { pets: [ { name: 'Splash', type: 'turtle', id: 100 }, undefined ] } to equal { pets: [ { name: 'Splash', type: 'turtle', id: 100 }, { name: 'avalanche', species: 'puppy', id: 101 } ] }
expected - actual
"id": 100
"name": "Splash"
"type": "turtle"
}
"id": 101
"name": "avalanche"
"species": "puppy"
at assert (node_modules/expect/lib/assert.js:29:9)
at Expectation.toEqual (node_modules/expect/lib/Expectation.js:81:30)
at Context. (test/index-test.js:14:107)
at callFn (node_modules/mocha-nocache/lib/runnable.js:286:21)
at Test.Runnable.run (node_modules/mocha-nocache/lib/runnable.js:279:7)
at Runner.runTest (node_modules/mocha-nocache/lib/runner.js:421:10)
at node_modules/mocha-nocache/lib/runner.js:528:12
at next (node_modules/mocha-nocache/lib/runner.js:341:14)
at node_modules/mocha-nocache/lib/runner.js:351:7
at next (node_modules/mocha-nocache/lib/runner.js:283:14)
at Immediate. (node_modules/mocha-nocache/lib/runner.js:319:5)
managePets reducer removes the pet when action type is REMOVE_PET and the action has a payload property of the id of pet to be removed:
Error: Expected { pets: [ { name: 'avalanche', species: 'puppy', id: 101 }, { name: 'sally', species: 'camel', id: 102 } ] } to equal { pets: [ { name: 'Splash', species: 'Turtle' }, { name: 'sally', species: 'camel', id: 102 } ] }
{
"pets": [
{
"id": 101
"name": "avalanche"
"species": "puppy"
"name": "Splash"
"species": "Turtle"
at assert (node_modules/expect/lib/assert.js:29:9)
at Expectation.toEqual (node_modules/expect/lib/Expectation.js:81:30)
at Context. (test/index-test.js:19:67)
at callFn (node_modules/mocha-nocache/lib/runnable.js:286:21)
at Test.Runnable.run (node_modules/mocha-nocache/lib/runnable.js:279:7)
at Runner.runTest (node_modules/mocha-nocache/lib/runner.js:421:10)
at node_modules/mocha-nocache/lib/runner.js:528:12
at next (node_modules/mocha-nocache/lib/runner.js:341:14)
at node_modules/mocha-nocache/lib/runner.js:351:7
at next (node_modules/mocha-nocache/lib/runner.js:283:14)
at Immediate. (node_modules/mocha-nocache/lib/runner.js:319:5)
render displays the state on the html:
TypeError: Cannot read property 'name' of undefined
at src/reducers/managePets.js:37:19
at Array.map (native)
at render (src/reducers/managePets.js:36:29)
at dispatch (src/reducers/managePets.js:31:3)
at Context. (test/index-test.js:48:5)
at callFn (node_modules/mocha-nocache/lib/runnable.js:286:21)
at Test.Runnable.run (node_modules/mocha-nocache/lib/runnable.js:279:7)
at Runner.runTest (node_modules/mocha-nocache/lib/runner.js:421:10)
at node_modules/mocha-nocache/lib/runner.js:528:12
at next (node_modules/mocha-nocache/lib/runner.js:341:14)
at node_modules/mocha-nocache/lib/runner.js:351:7
at next (node_modules/mocha-nocache/lib/runner.js:283:14)
at Immediate. (node_modules/mocha-nocache/lib/runner.js:319:5)
dispatch with render calls the render function which displays the updated html:
TypeError: Cannot read property 'name' of undefined
at src/reducers/managePets.js:37:19
at Array.map (native)
at render (src/reducers/managePets.js:36:29)
at Object.dispatch (src/reducers/managePets.js:31:3)
at Context. (test/index-test.js:63:13)
at callFn (node_modules/mocha-nocache/lib/runnable.js:286:21)
at Test.Runnable.run (node_modules/mocha-nocache/lib/runnable.js:279:7)
at Runner.runTest (node_modules/mocha-nocache/lib/runner.js:421:10)
at node_modules/mocha-nocache/lib/runner.js:528:12
at next (node_modules/mocha-nocache/lib/runner.js:341:14)
at node_modules/mocha-nocache/lib/runner.js:351:7
at next (node_modules/mocha-nocache/lib/runner.js:283:14)
at Immediate. (node_modules/mocha-nocache/lib/runner.js:319:5)
Seems like the solution branch should be passing the tests! I'm not sure if it's a problem with the solution or the tests.
Thanks!
found a work around by changing start alias in package.json to cmd.exe /C start <file>
i think there might be a better work around with xdg-open index.html
instead but that requires adding a BROWSER var to .bashrc which i couldn't get to work
Towards the end of the page there are two lines that say:
Action is defined because we passed { type: '@@init' } into dispatch. And the second argument, state, comes from the first line of our file. However, it's not defined.
State
is always the first argument as far as I can tell, not the second. Not a big deal, just caused me to double-take and re-read things.
We could try annotating parts of the code to cut down on some of the density of a few of the paragraphs. Inline comments are another thing we should try.
cc @JeffKatzy
Switches between state.count
and state.counter
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.