PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/js/todos/spec/view/app.js

http://github.com/pieter-vanderwerff/backbone-require-wire
JavaScript | 68 lines | 42 code | 22 blank | 4 comment | 0 complexity | 657c7aad22909670998404739e6135e8 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. define(
  2. [
  3. 'backbone',
  4. 'jquery',
  5. 'view/app'
  6. ],
  7. function( Backbone, $, View ) {
  8. describe( "App view", function() {
  9. it( "is a backbone view", function() {
  10. // It returned something
  11. expect( View ).toBeDefined();
  12. // Check its a backbone view instance
  13. expect( ( new View() ) instanceof Backbone.View ).toBeTruthy();
  14. } );
  15. // Test the render function
  16. it( "can render the template", function() {
  17. var view = new View(),
  18. collection = new ( Backbone.Collection.extend( {
  19. done: function() { return []; },
  20. remaining: function() { return []; }
  21. } ) )(),
  22. template = sinon.stub( view, 'statsTemplate' );
  23. view.stats = $( '<div></div>' ).get( 0 );
  24. view.allCheckbox = $( '<input type="checkbox" />' ).get( 0 );
  25. view.render( '', collection );
  26. view.render( '', { collection: collection } );
  27. view.render( '', {} ); // Should be rejected
  28. expect( template ).toHaveBeenCalledTwice();
  29. expect( view.allCheckbox.checked ).toBeTruthy();
  30. } );
  31. it( "trigger 'todoSubmission' event, on enter keypress", function() {
  32. var view = new View(),
  33. onEnter = { keyCode: 13 },
  34. onOtherKey = { keyCode: 66 },
  35. spy = sinon.spy();
  36. // Set the input element
  37. view.input = $( '<input />' ).val( 'test' );
  38. view.bind( 'todoSubmission', spy );
  39. view.createOnEnter( onEnter );
  40. view.createOnEnter( onOtherKey );
  41. expect( spy ).toHaveBeenCalledOnce(); // Only trigger the event for an enter press
  42. expect( spy ).toHaveBeenCalledWithExactly( { content: 'test' } ); // Should pass the content of the input
  43. expect( view.input.val() ).toEqual( '' ); // Reset input
  44. } );
  45. } );
  46. } );