Mocking $modal in AngularJS unit tests

前端 未结 4 1358
你的背包
你的背包 2020-11-27 11:30

I\'m writing a unit test for a controller that fires up a $modal and uses the promise returned to execute some logic. I can test the parent controller that fire

4条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 12:13

    Brant's answer was clearly awesome, but this change made it even better for me:

      fakeModal =
        opened:
          then: (openedCallback) ->
            openedCallback()
        result:
          finally: (callback) ->
            finallyCallback = callback
    

    then in the test area:

      finallyCallback()
    
      expect (thing finally callback does)
        .toEqual (what you would expect)
    

提交回复
热议问题