learn-elm-architecture-in-javascript
learn-elm-architecture-in-javascript copied to clipboard
app.update is not a function
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 keysok 1
todosandhashkeys are present. ok 2 model.todos is an Array
updatedefault 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$
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. 💡