mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 21:19:28 -06:00
d2a70bc42d
* 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>
29 lines
889 B
TypeScript
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);
|
|
}
|
|
});
|
|
});
|
|
});
|