Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Karma test : HttpBackend wrong error message thrown #326

Open
labrute opened this issue Feb 5, 2018 · 1 comment
Open

Karma test : HttpBackend wrong error message thrown #326

labrute opened this issue Feb 5, 2018 · 1 comment

Comments

@labrute
Copy link

labrute commented Feb 5, 2018

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.

@labrute
Copy link
Author

labrute commented Apr 20, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant