KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
We are in the process of learning Ember.js. We do all our development TDD, and want Ember.js to be no exception. We have experience building Backbone.js apps test-driven, so we are familiar with testing front-end code using Jasmine or Mocha/Chai. When figuring out how to test views, we ran into a problem when the template for the view uses has a #linkTo statement. Unfortunately we are unable to find good test examples and practices. This gist is our quest to get answers how to decently unit-test ember applications. When looking at the test for linkTo in Ember.js source code , we noticed it contains a full wiring of an ember app to support #linkTo . Does this mean we cannot stub this behaviour when testing a template? How do you create tests for ember views using template renders? Here is a gist with our test and a template that will make the test pass, and a template that will make it fail. view_spec.js.coffee # This test is made with Mocha / Chai, # With the chai-jquery and chai-changes extensions describe 'TodoItemsView', -> beforeEach -> testSerializer = DS.JSONSerializer.create primaryKey: -> 'id' TestAdapter = DS.Adapter.extend serializer: testSerializer TestStore = DS.Store.extend revision: 11 adapter: TestAdapter.create() TodoItem = DS.Model.extend title: DS.attr('string') store = TestStore.create() @todoItem = store.createRecord TodoItem title: 'Do something' @controller = Em.ArrayController.create content: [] @view = Em.View.create templateName: 'working_template' controller: @controller @controller.pushObject @todoItem afterEach -> @view.destro
Tags (comma-separated)
Save Edits
Cancel