model_binding.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. window.onload = function() {
  2. QUnit.test("model bindings and rebinding", assert => {
  3. var callback_count1 = 0
  4. var callbacks = App.Template._callbacks
  5. Object.keys(callbacks).forEach(function(key) {
  6. callback_count1 = callback_count1 + callbacks[key].length
  7. });
  8. assert.equal(callback_count1, 2)
  9. assert.equal(App.Template.SUBSCRIPTION_COLLECTION, undefined)
  10. App.Template.clearInMemory()
  11. assert.equal(App.Template.SUBSCRIPTION_COLLECTION, undefined)
  12. var callback_count2 = 0
  13. callbacks = App.Template._callbacks
  14. Object.keys(callbacks).forEach(function(key) {
  15. callback_count2 = callback_count2 + callbacks[key].length
  16. });
  17. assert.equal(callback_count2, callback_count1)
  18. var render = function() {}
  19. var subscribe_id = App.Template.subscribe(render, {initFetch: true})
  20. assert.ok(_.isObject(App.Template.SUBSCRIPTION_COLLECTION))
  21. assert.ok(!_.isEmpty(App.Template.SUBSCRIPTION_COLLECTION))
  22. var callback_count3 = 0
  23. callbacks = App.Template._callbacks
  24. Object.keys(callbacks).forEach(function(key) {
  25. callback_count3 = callback_count3 + callbacks[key].length
  26. });
  27. assert.equal(callback_count3, 6)
  28. App.Template.clearInMemory()
  29. assert.ok(_.isObject(App.Template.SUBSCRIPTION_COLLECTION))
  30. assert.ok(_.isEmpty(App.Template.SUBSCRIPTION_COLLECTION))
  31. var callback_count4 = 0
  32. callbacks = App.Template._callbacks
  33. Object.keys(callbacks).forEach(function(key) {
  34. callback_count4 = callback_count4 + callbacks[key].length
  35. });
  36. assert.equal(callback_count4, callback_count3)
  37. });
  38. }