Skip to content

Instantly share code, notes, and snippets.

@p-baleine
Created September 18, 2012 00:16
Show Gist options
  • Save p-baleine/3740556 to your computer and use it in GitHub Desktop.
Save p-baleine/3740556 to your computer and use it in GitHub Desktop.
Backbone.js app by BDD
buster.spec.expose();
var TodoList = require('todo/src/views/todo-list.js');
describe('TodoList view', function() {
it('TodoList関数が定義されていること', function() {
expect(TodoList).toBeFunction();
});
});
buster.spec.expose();
var Backbone = require('solutionio-backbone')
// Mock
var Todos = Backbone.Collection.extend();
var TodoList;
describe('TodoList view', function() {
before(function() {
specHelper.stubRequire.bind(this)({
'todo/src/collections/todos': Todos
});
specHelper.setupViewSpec();
TodoList = require('todo/src/views/todo-list.js');
});
it('TodoList関数が定義されていること', function() {
expect(TodoList).toBeFunction();
});
it('collectionプロパティを保持していること', function() {
var todoList = new TodoList();
expect(todoList.collection).toBeDefined();
});
});
var TodoList = require('todo/src/views/todo-list.js');
describe('TodoList view', function() {
/* ... */
it('collectionプロパティを保持していること', function() {
var todoList = new TodoList();
expect(todoList.collection).toBeDefined();
});
});
describe('TodoList view', function() {
/* ... */
describe('#render()', function() {
it('Todosコレクションにあるtodoを描画すること', function() {
var todoList = new TodoList();
this.spy(todoList, 'renderOne');
todoList.collection.add([{ content: 'hoge' }, { content: 'piyo' }]);
todoList.render();
expect(todoList.renderOne).toHaveBeenCalledThirce();
});
});
});
describe('TodoList view', function() {
/* ... */
describe('#renderOne()', function() {
/* ... */
it('描画したtodoをelにappendすること', function() {
var todoList = new TodoList()
, todo = new Backbone.Model({ content: 'hoge' });
this.spy(todoList.$el, 'append');
todoList.renderOne(todo);
expect(todoList.$el.append).toHaveBeenCalledOnce();
});
});
});
// Mock
var Todos = Backbone.Collection.extend()
, TodoItem = Backbone.View.extend();
var TodoList;
describe('TodoList view', function() {
before(function() {
specHelper.stubRequire.bind(this)({
'todo/src/collections/todos': Todos,
'todo/src/views/todo-item': TodoItem
});
specHelper.setupViewSpec();
TodoList = require('todo/src/views/todo-list.js');
});
/* ... */
describe('#renderOne()', function() {
it('todoを描画すること', function() {
var todoList = new TodoList()
, todo = new Backbone.Model({ content: 'hoge' });
this.spy(TodoItem.prototype, 'render');
this.spy(TodoItem.prototype, 'initialize');
todoList.renderOne(todo);
expect(Todoitem.prototype.render).toHaveBeenCalledOnce();
expect(Todoitem.prototype.initialize).toHaveBeenCalledOnce();
expect(TodoItem.prototype.initialize.args[0][0].get('content')).toEqual('hoge');
});
});
});
var Backbone = require('backbone.js');
var TodoList = module.exports = Backbone.View.extend();
var Backbone = require('backbone.js')
, Todos = require('../collections/todos');
var TodoList = module.exports = Backbone.View.extend({
initialize: function() {
this.collection = new Todos();
}
});
var TodoList = module.exports = Backbone.View.extend({
/* ... */
render: function() {
this.collection.each(function(model) {
this.renderOne(model);
}, this);
return this;
},
renderOne: function() {}
});
var Backbone = require('backbone.js')
, Todos = require('../collections/todos')
, TodoItem = require('../views/todo-item');
var TodoList = module.exports = Backbone.View.extend({
/* ... */
renderOne: function(model) {
var item = new TodoItem(model);
item.render();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment