{"id":14973435,"url":"https://github.com/amoldavsky/angular-mocks-async","last_synced_at":"2025-10-27T01:30:36.298Z","repository":{"id":57178765,"uuid":"52367835","full_name":"amoldavsky/angular-mocks-async","owner":"amoldavsky","description":"AngularJS ngMockE2E Async","archived":false,"fork":false,"pushed_at":"2018-04-09T14:15:47.000Z","size":666,"stargazers_count":12,"open_issues_count":7,"forks_count":41,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-02-01T01:25:11.636Z","etag":null,"topics":["angular","angular-mocks","angular-testing","angular1","e2e","httpbackend","mock","mocks","ngmock","ngmocke2e","promise"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amoldavsky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-23T15:11:47.000Z","updated_at":"2018-11-26T21:06:27.000Z","dependencies_parsed_at":"2022-08-31T03:31:25.399Z","dependency_job_id":null,"html_url":"https://github.com/amoldavsky/angular-mocks-async","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amoldavsky%2Fangular-mocks-async","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amoldavsky%2Fangular-mocks-async/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amoldavsky%2Fangular-mocks-async/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amoldavsky%2Fangular-mocks-async/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amoldavsky","download_url":"https://codeload.github.com/amoldavsky/angular-mocks-async/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238418225,"owners_count":19468868,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","angular-mocks","angular-testing","angular1","e2e","httpbackend","mock","mocks","ngmock","ngmocke2e","promise"],"created_at":"2024-09-24T13:48:42.813Z","updated_at":"2025-10-27T01:30:35.660Z","avatar_url":"https://github.com/amoldavsky.png","language":"JavaScript","readme":"# angular-mocks-async\nAngularJS ngMockE2E Async\n\u003cbr\u003e\u003cbr\u003e\n\n[![CircleCI](https://circleci.com/gh/amoldavsky/angular-mocks-async/tree/master.svg?style=shield)](https://circleci.com/gh/amoldavsky/angular-mocks-async)\n[![codecov](https://codecov.io/gh/amoldavsky/angular-mocks-async/branch/master/graph/badge.svg)](https://codecov.io/gh/amoldavsky/angular-mocks-async)\n\u003cbr\u003e\u003cbr\u003e\nTested for:\n\n![npm](https://img.shields.io/badge/angular-1.3.17-blue.svg)\n![npm](https://img.shields.io/badge/angular-1.4.0-blue.svg)\n![npm](https://img.shields.io/badge/angular-1.5.0-blue.svg)\n![npm](https://img.shields.io/badge/angular-1.6.0-blue.svg)\n\u003cbr\u003e\u003cbr\u003e\n\n\nAn abstraction on top of ngMockE2E to support async calls using promises. \n\nIf you need to make an async operation ( such as working with WebSQL / IndexedDB ) the orignial ngMockE2E will fall through and you will never have the chance to respond with your own response.\n\nngMockE2EAsync decorates the $httpBackend by utilizing promises. Responses can now be in a form of a promise where the $httpBackend will original function will not be called until your promise has been resolved. Once resolved the original $httpBackend APIs will be called and things will flow their natural ways back to the caller.\n\n## Demo\n[jsFiddle](https://jsfiddle.net/amoldavsky/omw8m23L/) [Plunker](https://plnkr.co/edit/IWtaW9?p=preview)\n\n## Install\n\n#### NPM\n```\nnpm install angular-mocks-async\n```\n\n#### HTML\n```html\n\u003cscript src=\"angular.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"angular-mocks.js\"\u003e\u003c/script\u003e\n\u003cscript src=\"//cdn.rawgit.com/amoldavsky/angular-mocks-async/master/src/angular-mocks-async.js\"\u003e\u003c/script\u003e\n```\n\n## Usage\n\nThe decorator exposes a new API\n```javascript\n\t$httpBackend.whenAsync()\n```\nWhich is equivalent to the $httpBackend.when() API but expects a promise in the .respond() function.\n\nHere is an example for an HTTP GET\n```javascript\n(function( ng ) {\n\n\tvar app = ng.module('myApp', ['ngMockE2E', 'ngMockE2EAsync'])\n\t\n\tapp.run( [ '$httpBackend', '$q', function( $httpBackend, $q ) {\n\n\t\t$httpBackend.whenAsync(\n\t\t\t    'GET',\n\t\t\t    new RegExp( 'http://api.example.com/user/.+$' )\n\t\t).respond( function( method, url, data, config ) {\n\n\t\t\tvar re = /.*\\/user\\/(\\w+)/;\n\t\t\tvar userId = parseInt(url.replace(re, '$1'), 10);\n\n\t\t\tvar response = $q.defer();\n\n\t\t\tsetTimeout( function() {\n\t\t\t    var data = {\n\t\t\t\tuserId: userId\n\t\t\t    };\n\t\t\t    response.resolve( [ 200, \"this is a mocked async GET response\", \"123\" ] );\n\t\t\t}, 1000 );\n\n\t\t\treturn response.promise;\n\n\t\t});\n\t\t$httpBackend.whenGET(/.*/).passThrough();\n\t        $httpBackend.whenPOST(/.*/).passThrough();\n\t        $httpBackend.whenPUT(/.*/).passThrough();\n\t        $httpBackend.whenJSONP(/.*/).passThrough();\n\t        $httpBackend.whenDELETE(/.*/).passThrough();\n\t\t\n\t\t$http({\n\t\t\turl: \"http://api.example.com/user/103\",\n\t\t\tmethod: 'GET'\n\t\t}).then( function( response ) {\n\t\t\talert( response.data );\n\t\t});\n\t}]);\n}(angular);\n```\nYou may use this API the same way for POST, PUT, UPDATE, and DELETE.\n\n## Details\n\nThe code adds a custom decorator function to the existing angular mock namespace which already hold similar decorator functions - angular.mock.$HttpBackendAsyncDecorator.\n\n## Developing \u0026 Testing\n\ngulpfile.js has the following tasks:\n```\ndist\ntest-unminified\ntest-minified\n```\nPlease be sure to run these tests when making changes\n\n\n## License\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famoldavsky%2Fangular-mocks-async","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famoldavsky%2Fangular-mocks-async","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famoldavsky%2Fangular-mocks-async/lists"}