angularjs - Testing Angular With Mocha and Chai -


i want test angular app yeoman use mocha phantom , chai assertion. when run sample test case test case not run shows phantomjs timed out due missing mocha run() call.non angular cases working fine in test case.

<!doctype html> <head>   <meta charset="utf-8">   <meta http-equiv="x-ua-compatible" content="ie=edge,chrome=1">   <title>mocha spec runner</title>   <link rel="stylesheet" href="lib/mocha/mocha.css"> </head> <body>   <div id="mocha"></div>   <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>   <script src="lib/mocha/mocha.js"></script>   <script>mocha.setup('bdd')</script>   <script src="lib/chai.js"></script>   <script>       expect = chai.expect;       assert = chai.assert;   </script>     <script>         function addsum(num1, num2) {             return num1 + num2;         }     </script>   <script>   (function() {     describe('give context', function() {         it('should simulate promise', inject(function ($q, $rootscope) {             assert.notstrictequal(3, '3', 'no coercion strict equality');          /*   var deferred = $q.defer();             var promise = deferred.promise;             var resolvedvalue;              promise.then(function(value) { resolvedvalue = value; });             expect(resolvedvalue).to.be.undefined;              // simulate resolving of promise             deferred.resolve(123);             // note 'then' function not called synchronously.             // because want promise api async, whether or not             // got called synchronously or asynchronously.             expect(resolvedvalue).to.be.undefined              // propagate promise resolution 'then' functions using $apply().             $rootscope.$apply();             expect(resolvedvalue).to.equal(123);*/         }));     });   })();   </script>       <!-- trigger mocha runner -->   <script src="runner/mocha.js"></script>  </body> </html> 

have tried using protractor? has been developed testing end end angularjs apps (by angularjs team). https://github.com/angular/protractor

it has it's own runner, install with:

npm install protractor -g 

and runner executed with:

protractor /configfile.cfg 

no need html page run tests.

the config file quite simple (you can see options in source code).

with that, you'll have spec defined as:

// mytest.js describe('angularjs homepage', function() {     it('should greet named user', function() {         browser.get('http://www.angularjs.org');         element(by.model('yourname')).sendkeys('julie');          var greeting = element(by.binding('yourname'));          expect(greeting.gettext()).toequal('hello julie!');       }); }); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -