promiseToDigest.test.ts 881 B

12345678910111213141516171819202122232425262728
  1. import { IScope } from 'angular';
  2. import { promiseToDigest } from './promiseToDigest';
  3. describe('promiseToDigest', () => {
  4. describe('when called with a promise that resolves', () => {
  5. it('then evalAsync should be called on $scope', async () => {
  6. const $scope: IScope = { $evalAsync: jest.fn() } as any as IScope;
  7. await promiseToDigest($scope)(Promise.resolve(123));
  8. expect($scope.$evalAsync).toHaveBeenCalledTimes(1);
  9. });
  10. });
  11. describe('when called with a promise that rejects', () => {
  12. it('then evalAsync should be called on $scope', async () => {
  13. const $scope: IScope = { $evalAsync: jest.fn() } as any as IScope;
  14. try {
  15. await promiseToDigest($scope)(Promise.reject(123));
  16. } catch (error) {
  17. expect(error).toEqual(123);
  18. expect($scope.$evalAsync).toHaveBeenCalledTimes(1);
  19. }
  20. });
  21. });
  22. });