2014-11-26 2 views
1

정말 맞춤 동작이있는 경로를 테스트하는 방법을 알아 내려고하고 있습니다.각도 테스트 ui-router 맞춤 인라인 컨트롤러

$stateProvider.state('oauth', { 
    url: '/oauth/callback', 
    controller: function($location, $window, ENV) { 
    if ($location.hash()) { 
     var pairs = $location.hash().split('&'); 
     var pair = pairs[0].split('='); 

     if (pair[1]) { 
     localStorage.accessToken = pair[1]; 
     $window.location.href = '/'; 
     } else { 
     $window.location.href = ENV.account; 
     } 
    } 
    } 
}); 

그러나, 지금까지 할 수 있었던 모두는 다음과 같습니다 :

describe('oauth', function() { 
    beforeEach(function() { 
    state = 'oauth'; 
    }); 

    it('should be the /oauth/callback url', function() { 
    expect($state.href(state)).toEqual('/oauth/callback'); 
    }); 
}); 

나는 그런 테스트 케이스를 처리하는 온라인 아무것도 찾을 수 없습니다 여기에 state의 코드입니다. 아이디어?

답변

1

$state.get()을 사용하면 상태 구성을 얻을 수 있습니다.

var config = $state.get('oauth'); 

다음

location.hash.and.returnValue('...'); 
expect(location.hash).toHaveBeenCalled(); 
expect($window.location.href).toBe('...'); 
일어날 것으로 예상하고 수동으로

var location = jasmine.createSpyObj('$location', ['hash']); 
$injector.instantiate(config.controller, {}, { 
    $location: location, 
    // ... (provide mocks of the services required by your controller here) 
}); 

을 컨트롤러의 인스턴스를, 컨트롤러의 종속성을 조롱하고 동작을 테스트