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 18, 2016
1 parent b97e562 commit d86cd7c
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 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,35 @@ 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(() => {
if (doTimeout && !timeoutId) {
timeoutId = window.setTimeout(function() {
timeoutId = null;
}, 10);
}
});
doTimeout = true;
});
}));
});

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

0 comments on commit d86cd7c

Please sign in to comment.