test sinonjs nodejs node jtest before async backbone.js jasmine sinon

backbone.js - sinonjs - Especificación de Sinon+Backbone falla bajo Jasmine Headless Webkit pero pasando con Jasmine independiente



nodejs test (1)

Tengo una especificación de colección de Backbone (todos, por supuesto) que usa Sinon para falsificar la respuesta del servidor con los datos del dispositivo. Esto pasa con Jasmine independiente, pero falla en mi configuración de Jasmine Headless Webkit.

El fracaso es esto:

Todos collection when fetching models from the server should parse todos from the response. Expected 0 to equal 2. (line ~58) expect(this.todos.length).toEqual(this.fixture.response.todos.length);

Sinon y mi dispositivo devuelven correctamente una reposesión falsa con 2 todos, pero no se analizan todos en la colección.

Hay un violín que muestra todo esto trabajando con Jasmine independiente aquí

Mi pedido de carga de My Web Head sin jaula es el siguiente:

clyde:backbone-jasmine andy$ jasmine-headless-webkit -l /Users/andy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/jasmine-core-1.1.0/lib/jasmine-core/jasmine.js /Users/andy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/jasmine-core-1.1.0/lib/jasmine-core/jasmine-html.js /Users/andy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/jasmine-core-1.1.0/lib/jasmine-core/jasmine.css /Users/andy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/jasmine-headless-webkit-0.8.4/vendor/assets/javascripts/jasmine-extensions.js /Users/andy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/jasmine-headless-webkit-0.8.4/vendor/assets/javascripts/intense.js /Users/andy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/jasmine-headless-webkit-0.8.4/vendor/assets/javascripts/headless_reporter_result.js /Users/andy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/jasmine-headless-webkit-0.8.4/vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js /Users/andy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/jasmine-headless-webkit-0.8.4/vendor/assets/javascripts/jsDump.js /Users/andy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/jasmine-headless-webkit-0.8.4/vendor/assets/javascripts/beautify-html.js /Users/andy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/jquery-rails-2.0.2/vendor/assets/javascripts/jquery.js /Users/andy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/jquery-rails-2.0.2/vendor/assets/javascripts/jquery_ujs.js /Users/andy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/jasmine-core-1.1.0/lib/jasmine-core/json2.js /Users/andy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/backbone-rails-0.9.2/vendor/assets/javascripts/underscore.js /Users/andy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/backbone-rails-0.9.2/vendor/assets/javascripts/backbone.js /Users/andy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/backbone-rails-0.9.2/vendor/assets/javascripts/backbone-rails.js /Users/andy/Code/backbone-jasmine/app/assets/javascripts/app/collections/todos.js.coffee /Users/andy/Code/backbone-jasmine/app/assets/javascripts/app/models/todo.js.coffee /Users/andy/Code/backbone-jasmine/app/assets/javascripts/application.js /Users/andy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/jasmine-spec-extras-0.0.2/vendor/assets/javascripts/jasmine-jquery.js /Users/andy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/jasmine-spec-extras-0.0.2/vendor/assets/javascripts/sinon.js /Users/andy/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/jasmine-spec-extras-0.0.2/vendor/assets/javascripts/jasmine-sinon.js /Users/andy/Code/backbone-jasmine/spec/javascripts/helpers/spec_helper.js.coffee /Users/andy/Code/backbone-jasmine/spec/javascripts/helpers/valid_response.js.coffee /Users/andy/Code/backbone-jasmine/spec/javascripts/fixtures/todos_fixture.js.coffee /Users/andy/Code/backbone-jasmine/spec/javascripts/app/models/todo_spec.js.coffee /Users/andy/Code/backbone-jasmine/spec/javascripts/app/collections/todos_spec.js.coffee

Y el código (también en el violín por supuesto):

# abbreviated todo model class window.Todo extends Backbone.Model # complete todos collection class window.Todos extends Backbone.Collection model: window.Todo url: "/todos" comparator: (todo) -> todo.get(''priority'') parse: (res) -> res.response.todos # spec/javascripts/fixtures/todos_fixture.js.coffee beforeEach -> @fixtures = Todos: valid: status: "OK" version: "1.0" response: todos: [ id: 1 title: "Paint the fence" , id: 2 title: "Wash the dog" ] # spec/javascripts/helpers/valid_response.js.coffee beforeEach -> @validResponse = (responseText) -> [ 200, "Content-Type": "application/json", JSON.stringify responseText ] # abbreviated todo spec (full spec in fiddle) describe "Todos collection", -> describe "when fetching models from the server", -> beforeEach -> @todo = sinon.stub(window, "Todo") @todos = new Todos() @fixture = @fixtures.Todos.valid @server = sinon.fakeServer.create() @server.respondWith "GET", "/todos", @validResponse(@fixture) afterEach -> @server.restore() @todo.restore() it "should parse todos from the response", -> @todos.fetch() @server.respond() expect(@todos.length).toEqual @fixture.response.todos.length expect(@todos.get(1).get(''title'')).toEqual @fixture.response.todos[0].title

Varias de las herramientas que se usan son nuevas para mí, así que realmente agradezco cualquier ayuda. ¡Gracias!


Tal vez hay algo asincrónico sucediendo en server.respond() . ¿Has probado esto?

it "should parse todos from the response", -> @todos.fetch() @server.respond() waits 500 runs -> expect(@todos.length).toEqual @fixture.response.todos.length expect(@todos.get(1).get(''title'')).toEqual @fixture.response.todos[0].title