jeudi 27 août 2015

Testing Angular route filter with Jasmine. Code works but cant make test pass

So my route filter is working as expected and I was writing some tests around it. I have several passing tests but for some reason I can't get this one test to pass. My route filter looks like this:

stripUs: ->
      resolve: ->
        resolution: ($location) ->
          urlParts = $location.$$path.split("/")
          if urlParts.indexOf('us') is 1
            $location.path(urlParts.slice(2,urlParts.length).join("/"))

The idea is to redirect /us/foo/bar urls to /foo/bar.

the tests I currently have passing for this filter are:

ddescribe 'stripUs', ->
    location = rootScope = null

    beforeEach inject ($location, $rootScope, initialDataService, ignoreHttpBackend) ->
      ignoreHttpBackend()
      location = $location
      rootScope = $rootScope

    it 'removes /us from /us/programming', ->
      location.path("/us/programming")
      rootScope.$digest()
      expect(location.path()).toEqual('/programming')

    it 'removes /us from /us/programming/**', ->
      location.path("/us/programming/sports")
      rootScope.$digest()
      expect(location.path()).toEqual('/programming/sports')

    it 'preserves route params', ->
      location.path("/us/programming/sports?affiliate=foo&&process=foobarred")
      rootScope.$digest()
      expect(location.path()).toEqual('/programming/sports?affiliate=foo&&process=foobarred')

The test I can't get to pass is:

it 'preserves route params', ->
      location.path("/us/programming?affiliate=foo")
      rootScope.$digest()
      expect(location.path()).toEqual('/programming?affiliate=foo')

the error message is:

Expected '/us/programming?affiliate=foo' to equal '/programming?affiliate=foo'

which would lead me to believe the code isn't working but it is if I actually try to visit the page. Additionally when I try to put a console log at the very top of the route filter, the log is never hit. I am new to testing in Jasmine and could use any help possible. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire