I am testing my angular applications with Jasmine and Karma.
My test looks like this:
Description ('login exam', function () {// mock our module first our test (module ('project') ) Var ctrl, scope; // $ $ injector and $ inject RootScope services // Before each block (inject (function ($ controller, $ rootsecope) {// $ root is a child's scope scope = $ rootScope. $ Create new (); // Controller ctrl = $ controller ('login controller', {$ scope: area});});) ('login wants to be successful ', Function () {scope.loginClick (' user ',' pass');});});
I have a login controller with the loginclick function, and within this function I have another function that is requesting POST The problem is that the internal function is never executed , I try console.log () to see that function is called, but without success My job looks like this:
app.controller ('Login Controller', ['$ scope', '$ http', '$ route', function ($ radius, $ http, $ Route) {Console.log ('Admin call'); // Yes it works ... $ scope.loginClick = function (username, password) {console.log ('call controller'); // yes it The handler works. REQPOST ('/ login', userdata, function (result) {console.log ('login request'); // no output is sent to the console})}}}}});
The Karma configuration file is included in the handler object start-up.
First of all, unless you have a good reason, $ http
Is a way to make back-end calls to callJJs, it also makes more testable.
In any case, you should copy the post-call into a unit-test, which you do not want to trust back-end
In your case, you have a spy () (First (each (injection (function ($ injector) {var $ controller = $} /
description ('login test', function () {before (Module ('project')); var ctrl, scope; Injector.get ('$ controller'); var $ rootScope = $ injector.get ('$ rootScope'); scope = $ rootsecope. $ New (); ctrl = $ Controller ('loginController', {$ scope: scope, });});; This ('test login', function () (spyOn (handler, 'reepost'); scope.loginClick ('user', 'pass'); hopefully (handler .reqPOST). CalledWith ('User', 'Pass');});});
Comments
Post a Comment