grafana/public/app/angular/promiseToDigest.test.ts
Ashley Harrison d2a70bc42d
Chore: more any/type assertion improvements (#57450)
* more friday any/type assertion improvements

* Apply suggestions from code review

Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com>

* Update public/app/angular/promiseToDigest.test.ts

Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com>

Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com>
2022-10-25 11:04:35 +02:00

29 lines
889 B
TypeScript

import { IScope } from 'angular';
import { promiseToDigest } from './promiseToDigest';
describe('promiseToDigest', () => {
describe('when called with a promise that resolves', () => {
it('then evalAsync should be called on $scope', async () => {
const $scope = { $evalAsync: jest.fn() } as jest.MockedObject<IScope>;
await promiseToDigest($scope)(Promise.resolve(123));
expect($scope.$evalAsync).toHaveBeenCalledTimes(1);
});
});
describe('when called with a promise that rejects', () => {
it('then evalAsync should be called on $scope', async () => {
const $scope = { $evalAsync: jest.fn() } as jest.MockedObject<IScope>;
try {
await promiseToDigest($scope)(Promise.reject(123));
} catch (error) {
expect(error).toEqual(123);
expect($scope.$evalAsync).toHaveBeenCalledTimes(1);
}
});
});
});