Skip to content

Commit

Permalink
fix(component-tester): remove incorrect behaviour where lifecycle met…
Browse files Browse the repository at this point in the history
…hods "bind" and "attached" were called twice by the bootstrap (#10)

* fix(component-tester): remove incorrect behaviour where lifecycle methods "bind" and "attached" were called twice by the bootstrap

Fixes #9

* fix(component-tester): fix lint errors

Fixes #9
  • Loading branch information
silbinarywolf authored Jan 31, 2019
1 parent 3f68b5a commit ab24fe9
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions lib/component-tester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,29 @@ export class ComponentTester<T = any> {
el.removeAttribute('au-target-id');
});

return aurelia.enhance(this.bindingContext, document.body).then(() => {
// NOTE: Jake: 2019-01-31 - #8
// Consider allowing bindingContext to be a function as well.
// A potential benefit is that you can use "Container.instance.get" within the context
const bindingContext = this.bindingContext;
// const bindingContext = typeof(this.bindingContext) === 'function' ? this.bindingContext() : this.bindingContext;

return aurelia.enhance(bindingContext, document.body).then(() => {
// NOTE: Jake: 2018-12-19
// These are in the original aurelia-testing library
// this.rootView = aurelia.root;
// this.element = this.host.firstElementChild as Element;

if (view.bind) {
view.bind(this.bindingContext);
}
if (view.attached) {
view.attached();
}
// NOTE: Jake: 2019-01-31 - #9
// We used to call these manually like the aurelia-testing library,
// however aurelia.enhance() calls lifecycle methods already, so this was
// actually causing bugs where attached() was being called twice.
// if (view.bind) {
// view.bind(bindingContext);
// }
// if (view.attached) {
// view.attached();
// }

componentsAttached.push(view);

// Wait 4 frames, this allows us to do "hacky" CSS sizing calculations
Expand Down

0 comments on commit ab24fe9

Please sign in to comment.