overleaf/services/web/test/frontend/shared/hooks/use-callback-handlers.test.js
Timothée Alby 44eca312ff Merge pull request #6053 from overleaf/ta-pdf-detach-tests
PDF Detach Misc Tests

GitOrigin-RevId: 9615c8fdfd8964a9c63d7c91e4596d397a1d35dc
2021-12-15 09:04:46 +00:00

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)
})
})