Mocha Chai test case for angular configuration file

后端 未结 2 819
盖世英雄少女心
盖世英雄少女心 2021-01-26 10:06

I am getting a hard time to resolve mocha chai test case for angular js configuration file .

angular.module(\'myApp.myModule\', []).config(function ($stateProvid         


        
相关标签:
2条回答
  • 2021-01-26 10:52

    I did it like

    it('should load the page.', inject(function ($state) {
        var state = $state.get('selectLine');
        assert.isDefined(state.templateUrl()); 
        expect(state.templateUrl()).to.equal('scripts/select-line-module/views/select-line.html');
    }));
    

    This works for me

    0 讨论(0)
  • 2021-01-26 11:00

    What you can do is to inject $location and $route service into your test. Setup a whenGET to intercept the actual request and then check the $location and $route configuration after the transition is complete. I did something similar earlier

    it("should load the page.", inject(function ($rootScope, $location, $route, $httpBackend) {
            $httpBackend.whenGET("scripts/my-module/views/my-module.html").respond("<div/>");
            $location.path("/myModule");
            $rootScope.$digest();
            expect($location.path()).toBe("/myModule");
        }));
    

    I was using $route service you would require $state service.

    0 讨论(0)
提交回复
热议问题