Comparing version 0.10.30 to 0.10.31
{ | ||
"name": "derby", | ||
"description": "MVC framework making it easy to write realtime, collaborative applications that run in both Node.js and browsers.", | ||
"version": "0.10.30", | ||
"version": "0.10.31", | ||
"homepage": "http://derbyjs.com/", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -44,2 +44,16 @@ var ComponentHarness = require('./ComponentHarness'); | ||
// Executes the parts of `Page#destroy` pertaining to the model, which get | ||
// re-done when a new Page gets created on the same model. Normally, using | ||
// `Page#destroy` would be fine, but the `.to.render` assertion wants to do | ||
// 3 rendering passes on the same data, so we can't completely clear the | ||
// model's state between the rendering passes. | ||
function resetPageModel(page) { | ||
page._removeModelListeners(); | ||
for (var componentId in page._components) { | ||
var component = page._components[componentId]; | ||
component.destroy(); | ||
} | ||
page.model.silent().destroy('$components'); | ||
} | ||
if (Assertion) { | ||
@@ -80,3 +94,4 @@ Assertion.addMethod('html', function(expected, options) { | ||
// Render to a HTML string. | ||
var htmlString = harness.renderHtml(options).html; | ||
var renderResult = harness.renderHtml(options); | ||
var htmlString = renderResult.html; | ||
@@ -110,2 +125,4 @@ // Normalize `htmlString` into the same form as the DOM would give for `element.innerHTML`. | ||
resetPageModel(renderResult.page); | ||
// Check DOM rendering is also equivalent. | ||
@@ -127,3 +144,4 @@ // This uses the harness "pageRendered" event to grab the rendered DOM *before* any component | ||
}); | ||
harness.renderDom(options); | ||
renderResult = harness.renderDom(options); | ||
resetPageModel(renderResult.page); | ||
@@ -130,0 +148,0 @@ // Try attaching. Attachment will throw an error if HTML doesn't match |
@@ -218,2 +218,27 @@ var expect = require('chai').expect; | ||
}); | ||
it('cleans up component state between render passes', function() { | ||
function Box() {} | ||
Box.view = { | ||
is: 'box', | ||
source: '<index:><div class="box">{{greeting}}</div>' | ||
}; | ||
Box.prototype.init = function() { | ||
var initialName = this.model.scope('_page.initialName').get(); | ||
expect(initialName).to.equal('Spot'); | ||
this.model.set('name', initialName); | ||
this.model.start('greeting', ['name'], function(name) { | ||
// This assertion ensures that the reactive function isn't called after | ||
// the component gets destroyed. | ||
expect(name).to.equal('Spot'); | ||
return 'Hello, ' + name; | ||
}); | ||
}; | ||
var harness = runner.createHarness('<view is="box" />', Box); | ||
// Have the test depend on state in `_page` to make sure it's not cleared | ||
// between rendering passes in `.to.render`. | ||
harness.model.set('_page.initialName', 'Spot'); | ||
expect(harness).to.render('<div class="box">Hello, Spot</div>'); | ||
}); | ||
}); | ||
@@ -220,0 +245,0 @@ |
225562
5823