angularjs - How to mock service in angularAMD with karma/jasmine? -
I have a project using AngularAMD / RequireJS / Karma / Jasmin, I have basic configuration to do all the work, I have:
I have:
I have:
Services / MyService.js defined ([ 'App'], function (app) {app.factory ('myService', ['$ document', function ($ document) {function add (html)) {$ Document.find ('body'). Attachments (html );} Return {add: add};}]);}); // Define the test (['angularAMD', 'angular mocks', 'application', 'services / MyService'], function (aamd, joke, not app) {Description ('MyService' function () {var myBodyMock = {Enclosed: function () {}}; myDocumentMock = {looks: function (sEL) {// it is never called console.log ('selector:' + sel); return myBodyMock;}}; SVC; beforeEach (function () {// ({$ provide.value ('$ document', myDocumentMock) function ($ rendered);}); NG-standard way to ridicule a service through fake mocks.module Try // Rescue my bets - incomplete The attempt to hijra, as well as NG-Fake Amed.value ('$ document', myDocumentMock);}); First of each (F) (aamd.inject (['myService', function (myService) {svc = MyService;}]);}); It is expected that the injection of $ $ document is fake; function () {// use SVC spyOn (myDocumentMock, 'sounds') andCallThrough (); SpyOn (myBodyMock, 'Attached'); svc.add ('<' & lt; / p & gt;); Hope (myDocumentMock.find) .toHaveBeenCalledWith ('body'); Hope (myBockMock.append) .toHaveBeenCalledWith ('<< & gt; & lt; / p & gt;'); }); }); }); Do anyone know where I'm going wrong? Any help will be very much appreciated.
angular is not asynchronous, I think good idea is not used both. If you are trying to reach a good modulation method, okay, but use the RequireJS adapter to insert everything on your browser and create everything else, and about the test, I think you can use your module You can already use the RequireJS adapter to create, it will let you "free from the usual JS environment tests"
Comments
Post a Comment