dwyl / learn-elm-architecture-in-javascript

:unicorn: Learn how to build web apps using the Elm Architecture in "vanilla" JavaScript (step-by-step TDD tutorial)!
https://todomvc-app.herokuapp.com
GNU General Public License v2.0
213 stars 19 forks source link

app.update is not a function #72

Open gracezhouu opened 4 years ago

gracezhouu commented 4 years ago

Hi Guys When I go to the second step, and basic update function and run the test,

/**
 * `update` transforms the `model` based on the `action`.
 * @param {String} action - the desired action to perform on the model.
 * @param {Object} model - the App's (current) model (or "state").
 * @return {Object} new_model - the transformed model.
 */
function update(action, model) {
 switch (action) {                  // action (String) determines which case
   default:                         // if action unrecognised or undefined,
     return model;                  // return model unmodified
 }    // default? https://softwareengineering.stackexchange.com/a/201786/211301
}

it supposed to pass the test, but there is the following error message, anyone know why?

TAP version 13

model (Object) has desired keys

ok 1 todos and hash keys are present. ok 2 model.todos is an Array

update default case should return model unmodified

/Users/rushlin/Downloads/mystuff/javascript-todo-list/test/todo-app1.test.js:19 const unmodified_model = app.update('UNKNOWN_ACTION', model); ^

TypeError: app.update is not a function at Test. (/Users/rushlin/Downloads/mystuff/javascript-todo-list/test/todo-app1.test.js:19:32) at Test.bound [as _cb] (/Users/rushlin/node_modules/tape/lib/test.js:84:32) at Test.run (/Users/rushlin/node_modules/tape/lib/test.js:101:31) at Test.bound [as run] (/Users/rushlin/node_modules/tape/lib/test.js:84:32) at Immediate.next (/Users/rushlin/node_modules/tape/lib/results.js:83:19) at processImmediate (internal/timers.js:456:21) shanshandeMacBook-Pro:javascript-todo-list rushlin$

nelsonic commented 4 years ago

Hi @gracezhouu thanks for opening this issue to let us know you are stuck. 👍 From your stack trace you appear to be following the Todo List Tutorial: https://github.com/dwyl/javascript-todo-list-tutorial is that correct?

Please confirm that you have exported the update function in your /lib/todo-app.js e.g:

https://github.com/dwyl/javascript-todo-list-tutorial/blob/e6736add9df1f46035f8a9d1dbdc14c71a7cdb41/lib/todo-app.js#L344-L354

If update is not exported at the end of your /lib/todo-app.js file then it won't be accessible in your tests so you will see this app.update is not a function error.

If possible, commit your code to GitHub so we can help you debug it much faster. 💡