Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(View): preserve bindingContext while unbinding
fixes aurelia/framework#372
- Loading branch information
Showing
2 changed files
with
36 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {View} from '../src/view'; | ||
|
||
describe('View', () => { | ||
it('binds and unbinds', () => { | ||
let view; | ||
let bindingContext = {}; | ||
let overrideContext = {}; | ||
let viewFactory = { resources: { _invokeHook: jasmine.createSpy('_invokeHook') } }; | ||
let fragment = {}; | ||
let controllers = [{ bind: jasmine.createSpy('bind'), unbind: jasmine.createSpy('unbind') }]; | ||
let bindings = [{ | ||
bind: jasmine.createSpy('bind'), | ||
unbind: jasmine.createSpy('unbind').and.callFake(function() { | ||
// the view's bindingContext needs to be preserved while bindings are unbinding. | ||
expect(view.bindingContext).toBe(bindingContext); | ||
expect(view.overrideContext).toBe(overrideContext); | ||
}) | ||
}]; | ||
let children = [{ bind: jasmine.createSpy('bind'), unbind: jasmine.createSpy('unbind') }]; | ||
let contentSelectors = []; | ||
view = new View(viewFactory, fragment, controllers, bindings, children, contentSelectors); | ||
view.bind(bindingContext, overrideContext); | ||
expect(viewFactory.resources._invokeHook).toHaveBeenCalledWith('beforeBind', view); | ||
expect(controllers[0].bind).toHaveBeenCalledWith(view); | ||
expect(bindings[0].bind).toHaveBeenCalledWith(view); | ||
expect(children[0].bind).toHaveBeenCalledWith(bindingContext, overrideContext, true); | ||
view.unbind(); | ||
expect(viewFactory.resources._invokeHook).toHaveBeenCalledWith('beforeUnbind', view); | ||
expect(controllers[0].unbind).toHaveBeenCalled(); | ||
expect(bindings[0].bind).toHaveBeenCalled(); | ||
expect(children[0].bind).toHaveBeenCalled(); | ||
}); | ||
}); |