tooltip.spec.js 30.6 KB
Newer Older
Johann-S's avatar
Johann-S committed
1001
1002
      jQueryMock.fn.tooltip.call(jQueryMock)

1003
      expect(Tooltip.getInstance(div)).toEqual(tooltip)
Johann-S's avatar
Johann-S committed
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
    })

    it('should call a tooltip method', () => {
      fixtureEl.innerHTML = '<div></div>'

      const div = fixtureEl.querySelector('div')
      const tooltip = new Tooltip(div)

      spyOn(tooltip, 'show')

1014
      jQueryMock.fn.tooltip = Tooltip.jQueryInterface
Johann-S's avatar
Johann-S committed
1015
1016
1017
1018
      jQueryMock.elements = [div]

      jQueryMock.fn.tooltip.call(jQueryMock, 'show')

1019
      expect(Tooltip.getInstance(div)).toEqual(tooltip)
Johann-S's avatar
Johann-S committed
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
      expect(tooltip.show).toHaveBeenCalled()
    })

    it('should do nothing when we call dispose or hide if there is no tooltip created', () => {
      fixtureEl.innerHTML = '<div></div>'

      const div = fixtureEl.querySelector('div')

      spyOn(Tooltip.prototype, 'dispose')

1030
      jQueryMock.fn.tooltip = Tooltip.jQueryInterface
Johann-S's avatar
Johann-S committed
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
      jQueryMock.elements = [div]

      jQueryMock.fn.tooltip.call(jQueryMock, 'dispose')

      expect(Tooltip.prototype.dispose).not.toHaveBeenCalled()
    })

    it('should throw error on undefined method', () => {
      fixtureEl.innerHTML = '<div></div>'

      const div = fixtureEl.querySelector('div')
      const action = 'undefinedMethod'

1044
      jQueryMock.fn.tooltip = Tooltip.jQueryInterface
Johann-S's avatar
Johann-S committed
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
      jQueryMock.elements = [div]

      try {
        jQueryMock.fn.tooltip.call(jQueryMock, action)
      } catch (error) {
        expect(error.message).toEqual(`No method named "${action}"`)
      }
    })
  })
})
For faster browsing, not all history is shown. View entire blame