Skip to content

Commit

Permalink
test(upgrade): async operations in watchers should not trigger digest
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin committed Dec 16, 2016
1 parent 5d5aa52 commit 124b305
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion modules/@angular/upgrade/test/upgrade_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export function main() {
});
}));


it('should propagate changes to a downgraded component inside the ngZone', async(() => {
let appComponent: AppComponent;
let upgradeRef: UpgradeAdapterRef;
Expand Down Expand Up @@ -234,6 +234,38 @@ export function main() {
appComponent.value = 5;
});
}));

it('should not trigger $digest from an async operation in a watcher', async(() => {
@Component({selector: 'my-app', template: ''})
class AppComponent {
}

@NgModule({declarations: [AppComponent], imports: [BrowserModule]})
class Ng2Module {
}

const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => Ng2Module));
const ng1Module = angular.module('ng1', []).directive(
'myApp', adapter.downgradeNg2Component(AppComponent));

const element = html('<my-app></my-app>');

adapter.bootstrap(element, ['ng1']).ready((ref) => {
let doTimeout = false;
let timeoutId: number;
ref.ng1RootScope.$watch(() => {
console.log('watching');
if (doTimeout && !timeoutId) {
console.log('creating timeout');
timeoutId = window.setTimeout(function() {
console.log('handling timeout');
timeoutId = null;
}, 10);
}
});
doTimeout = true;
});
}));
});

describe('downgrade ng2 component', () => {
Expand Down

0 comments on commit 124b305

Please sign in to comment.