Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

bug(ngMock): errors thrown to reject promises are not caught #7187

Closed
@bclinkinbeard

Description

@bclinkinbeard

Request Type: bug

How to reproduce: Include angular and angular-mocks on a page and run this code. Error is printed to the console even though the promise chain is configured to recover from the error.

var inject = angular.injector(['ng', 'ngMock']).invoke

inject(function ($http, $httpBackend) {

  $httpBackend.expectGET('http://example.com').respond('foo')

  $http.get('http://example.com')
    .then(function (result) {
      throw new Error('Intentional rejection')
    })
    .then(null, function (err) {
      console.log(err);
    })

  $httpBackend.flush()
})

Component(s): ngMock

Impact: small

Complexity: medium

This issue is related to:

Detailed Description:

This behavior can be corrected by wrapping a try...catch around the call to callback around line 1124 of angular-mocks, but that breaks 3 $compile tests and I'm not sure what to do with the caught error.

In its current state, unit testing promise chains must be done with ngMockE2E.

Other Comments:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions