stefanpenner / es6-promise

A polyfill for ES6-style Promises

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Karma test : HttpBackend wrong error message thrown

labrute opened this issue · comments

commented

Hi,
I m using es6-promise for my karma tests and i have discovered and strange behavior on with jasmine tests.
This bug appear when I'm catching the http error in my code.

Example :
Code

this.http.post("api/persons", person)
.then(() => {
	console.log("Saved");
}, (error: IHttpPromiseCallbackArg<any>) => {
	console.log("Error");
});

Test

$httpBackend.expectPOST('api/persons', null).respond(200);
$httpBackend.flush();

I'm using angular mock for all my backend tests, and if the parameter is not the expected one I have this error :

Error: No pending request to flush ! (line 1852)
	flush@node_modules/angular-mocks/angular-mocks.js:1852:83
	invoke@node_modules/angular/angular.js:5040:24
	WorkFn@node_modules/angular-mocks/angular-mocks.js:3183:26
	inject@node_modules/angular-mocks/angular-mocks.js:3150:28
	eval code
	eval@[native code]
	evaluate@node_modules/systemjs/dist/system.src.js:2818:16
	node_modules/systemjs/dist/system.src.js:3586:29
	dynamicExecute@node_modules/systemjs/dist/system.src.js:1142:30
	doEvaluate@node_modules/systemjs/dist/system.src.js:1089:27
	ensureEvaluate@node_modules/systemjs/dist/system.src.js:997:23
	node_modules/systemjs/dist/system.src.js:610:28
	tryCatch@node_modules/es6-promise/dist/es6-promise.auto.js:416:20
	invokeCallback@node_modules/es6-promise/dist/es6-promise.auto.js:431:21
	publish@node_modules/es6-promise/dist/es6-promise.auto.js:399:21
	flush@node_modules/es6-promise/dist/es6-promise.auto.js:126:13

Now, if I remove the catch, I have the expected message :

Error: Expected POST api/persons with different data

My environnement :

"angular": "1.6.6",
"es6-shim": "0.35.3",
"systemjs": "0.20.19"
"angular-mocks": "^1.6.7",
"gulp": "3.9.1",
"karma": "^1.7.1",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.1.1",
"karma-phantomjs-launcher": "^1.0.4",
"karma-sourcemap-loader": "^0.3.7",
"phantomjs-prebuilt": "^2.1.16",
"run-sequence": "2.2.0",
"systemjs-builder": "0.16.12",
"tslint": "3.15.1",
"typescript": "1.8.10"

$ npm -v
3.10.10
$ node -v
v6.9.5

Thx for your help.

commented

I have updated es6-promise to v4.2.4 and the problem is the same :

Error: No pending request to flush ! (line 1852) flush@node_modules/angular-mocks/angular-mocks.js:1852:83 invoke@node_modules/angular/angular.js:5040:24 WorkFn@node_modules/angular-mocks/angular-mocks.js:3183:26 inject@node_modules/angular-mocks/angular-mocks.js:3150:28 eval code eval@[native code] evaluate@node_modules/systemjs/dist/system.src.js:2818:16 node_modules/systemjs/dist/system.src.js:3586:29 dynamicExecute@node_modules/systemjs/dist/system.src.js:1142:30 doEvaluate@node_modules/systemjs/dist/system.src.js:1089:27 ensureEvaluate@node_modules/systemjs/dist/system.src.js:997:23 node_modules/systemjs/dist/system.src.js:610:28 tryCatch@node_modules/es6-promise/dist/es6-promise.auto.js:409:20 invokeCallback@node_modules/es6-promise/dist/es6-promise.auto.js:424:21 publish@node_modules/es6-promise/dist/es6-promise.auto.js:398:21 flush@node_modules/es6-promise/dist/es6-promise.auto.js:128:13