bitovi / bitovi/funcunit

Cannot get "type()" in Funcunit to work for JavascriptMVC rapid start todos tutorial.

Open
#116 1 comment 0 reactions 0 assignees View on GitHub
p2
Dominant language
JavaScript
Stars
571
Forks
370
PR merge metrics
No merged PRs in 30d

Description

Hello,

Great work on the JavaScriptMVC!
I followed the [tutorial](http://www.javascriptmvc.com/docs/rapidstart.html) on JavaScriptMVC.com to build the basic Todo app. I made some modifications to the code.

todos.js

```
steal('can',
'./todos.ejs',
'can/util/fixture',
function (can, todosEJS) {
Todo = can.Model.extend({
findAll: "GET /todos",
findOne: "GET /todos/{id}",
create: "POST /todos",
update: "PUT /todos/{id}",
destroy: "DELETE /todos/{id}"
}, {});
var TODOS = [
{
id: 1,
name: "wake up"
},
{
id: 2,
name: "take out trash"
},
{
id: 3,
name: "do dishes"
}
];
can.fixture({
// findAll
"GET /todos": function () {
return TODOS;
},
// findOne
"GET /todos/{id}": function (orig) {
// return the one item with that unique ID
var result = $.grep(TODOS, function(e){
return e.id == (+orig.data.id);
});
return result[0];
},
// create
"POST /todos": function (request) {
TODOS.push(request.data);
return {
id: TODOS.length
};
},
// update
"PUT /todos/{id}": function (orig) {
TODOS[(+orig.data.id) - 1].name = orig.data.name;
return TODOS[(+orig.data.id) - 1];
},
// destroy
"DELETE /todos/{id}": function (orig) {
TODOS.splice(((+orig.data.id) - 1), 1);
console.log(TODOS);
return {};
}
});

var Todos = can.Control({
init: function (element) {
Todo.findAll({}, function (todos) {
element.html(todosEJS(todos));
});
},
"li click": function (li) {
li.trigger('selected', li.data('todo'));
},
"li .destroy click": function (el, ev) {
// get the li element that has the model
var li = el.closest('li');

// get the model and destroy it
li.data('todo').destroy();
}
});

Editor = can.Control({
todo: function (todo) {
this.options.todo = todo;
this.on();
this.setName();
},
// a helper that sets the value of the input
// to the todo's name
setName: function () {
this.element.val(this.options.todo.name);
},
// listen for changes in the todo
// and update the input
"{todo} updated": function () {
this.setName();
},
// when the input changes
// update the todo instance
"change": function () {
var todo = this.options.todo;
todo.attr('name', this.element.val());
todo.save();
}
});

Routing = can.Control({
init: function () {
this.editor = new Editor("#editor");
new Todos("#todos");
},
// the index page
"route": function () {
$("#editor").hide();
},
"todos/:id route": function (data) {
$("#editor").show();
console.log(data);
Todo.findOne(data, $.proxy(function (todo) {
this.editor.todo(todo);
}, this));
},
".todo selected": function (el, ev, todo) {
can.route.attr('id', todo.id);
}
});

// create routing controller
new Routing(document.body);
});

```

todos.html

```



    steal = {
    suffix: "0.0.1"
    }


    ```

    todos.ejs

    ```
    <% this.each(function(todo){ %>

  • el.data('todo', todo) %> class='todo'>
    <%= todo.attr('name') %>
    X

  • <% }) %>

    ```

    todos_test.js

    ```
    steal('funcunit', function (S) {

    module('todos', {
    setup: function () {
    S.open("//todos/todos.html");
    },
    teardown: function () {
    // S.win.close();
    }
    });

    test('verify first todo', function () {
    S(".todo:first").click();

    S('#editor')
    .visible()
    .click()
    .type(" one[enter]")
    .val('wake up one');
    });

    });
    ```

    test.html

    ```



    ```

    I'm trying to write a unit test that gives the UPDATE route coverage. However, the test never writes " one" in the input box and the test always fails. Could you please help me find what I'm missing?

    Best,
    Aaron

    Contributor guide

    No contributing guide indexed for this repository

    Assessment

    This issue has not been assessed yet.

    Get new issues in your inbox

    A short digest of beginner-friendly GitHub issues.