Mocking AngularJS module dependencies in Jasmine unit tests

前端 未结 3 958
北恋
北恋 2020-11-30 18:57

I\'m attempting to unit test controller code inside a module that takes other modules as dependencies, but haven\'t been able to figure out how to mock them properly.

3条回答
  •  感情败类
    2020-11-30 19:45

    I recently released ngImprovedTesting that should make mock testing in AngularJS way easier.

    In your case just use the following in your Jasmine test:

    beforeEach(ModuleBuilder.forModule('events').serviceWithMocks('eventsCtrl').build());
    

    For more information about ngImprovedTesting check out its introductory blog post: http://blog.jdriven.com/2014/07/ng-improved-testing-mock-testing-for-angularjs-made-easy/

提交回复
热议问题