最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Get error when try to use jasmine and angular - Stack Overflow

programmeradmin4浏览0评论

When I try to use $httpBackend.flush(); I get error TypeError: $browser.cookies is not a function. I can't find any information about this kind of error and any solutions.

describe("someText", function() {
    var $httpBackend;
    var someManager;
    var authRequestHandler;

    var dataMockup = [];

    beforeEach(function(){
        module('app');

        inject(function($injector){
            $httpBackend = $injector.get('$httpBackend');
            someManager = $injector.get('someManager');

            authRequestHandler = $httpBackend.when('GET', 'someUrl.php')
                .respond(dataMockup);
        });
    });

    it('test first action', function() {
        $httpBackend.expectGET('someUrl.php');
        messageManager.loadData();
        $httpBackend.flush(); // There i got error
    });
});
  • Angular: 1.3.15
  • Jasmine: 2.3.4

When I try to use $httpBackend.flush(); I get error TypeError: $browser.cookies is not a function. I can't find any information about this kind of error and any solutions.

describe("someText", function() {
    var $httpBackend;
    var someManager;
    var authRequestHandler;

    var dataMockup = [];

    beforeEach(function(){
        module('app');

        inject(function($injector){
            $httpBackend = $injector.get('$httpBackend');
            someManager = $injector.get('someManager');

            authRequestHandler = $httpBackend.when('GET', 'someUrl.php')
                .respond(dataMockup);
        });
    });

    it('test first action', function() {
        $httpBackend.expectGET('someUrl.php');
        messageManager.loadData();
        $httpBackend.flush(); // There i got error
    });
});
  • Angular: 1.3.15
  • Jasmine: 2.3.4
Share Improve this question asked May 27, 2015 at 16:16 gregurcogregurco 1631 silver badge7 bronze badges 2
  • Make sure you have the right version of angular mocks file as well. cdnjs.cloudflare./ajax/libs/angular.js/1.3.15/… – PSL Commented May 27, 2015 at 16:17
  • 1 @PSL, thanks. I didn't noticed that. – gregurco Commented May 27, 2015 at 16:21
Add a ment  | 

1 Answer 1

Reset to default 18

I believe you are using the angular mocks for version 1.4.x, and your code is using angular 1.3.15. Please check that you are using the mocks for the version you are implementing in your application. Also it is always good to provide your jasmine test configuration file.

发布评论

评论列表(0)

  1. 暂无评论