Skip to content

Instantly share code, notes, and snippets.

@jepetko
Created September 23, 2016 21:40
Show Gist options
  • Save jepetko/2ddc88dd0a86728e01750ec4e6cb9e9f to your computer and use it in GitHub Desktop.
Save jepetko/2ddc88dd0a86728e01750ec4e6cb9e9f to your computer and use it in GitHub Desktop.
describe('change detection', () => {
let failure = 'There should be the exception: Expression has changed after it was checked';
let spy: any;
let myIt: any;
beforeEach(() => {
fixture.autoDetectChanges(true);
patchChangeDetection();
let errHandler = (err: any) => {
myIt.result.failedExpectations = []; // clear the failed expectations. fail again ...
if (err.error.message.indexOf('Expression has changed after it was checked') === -1) {
fail(failure);
}
};
spy = jasmine.createSpy('errHandler', errHandler).and.callThrough();
});
myIt = it(`throws a "change detection error" if the fruit price > 100
and and the user does not provide a budget value`, () => {
fillValue('#budget', 100);
fillValue('#fruit0', 100); // apples
fixture.ngZone.onError.subscribe(spy);
clearBudgetAndLeave();
expect(spy.calls.count()).toBe(1, failure); // error occurred => spec passed
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment