mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-14 20:50:57 -05:00
44eca312ff
PDF Detach Misc Tests GitOrigin-RevId: 9615c8fdfd8964a9c63d7c91e4596d397a1d35dc
34 lines
1 KiB
JavaScript
34 lines
1 KiB
JavaScript
import sinon from 'sinon'
|
|
import { renderHook } from '@testing-library/react-hooks'
|
|
import useCallbackHandlers from '../../../../frontend/js/shared/hooks/use-callback-handlers'
|
|
|
|
describe('useCallbackHandlers', function () {
|
|
it('adds, removes and calls all handlers without duplicate', async function () {
|
|
const handler1 = sinon.stub()
|
|
const handler2 = sinon.stub()
|
|
const handler3 = sinon.stub()
|
|
|
|
const { result } = renderHook(() => useCallbackHandlers())
|
|
|
|
result.current.addHandler(handler1)
|
|
result.current.deleteHandler(handler1)
|
|
result.current.addHandler(handler1)
|
|
|
|
result.current.addHandler(handler2)
|
|
result.current.deleteHandler(handler2)
|
|
|
|
result.current.addHandler(handler3)
|
|
result.current.addHandler(handler3)
|
|
|
|
result.current.callHandlers('foo')
|
|
result.current.callHandlers(1337)
|
|
|
|
sinon.assert.calledTwice(handler1)
|
|
sinon.assert.calledWith(handler1, 'foo')
|
|
sinon.assert.calledWith(handler1, 1337)
|
|
|
|
sinon.assert.notCalled(handler2)
|
|
|
|
sinon.assert.calledTwice(handler3)
|
|
})
|
|
})
|