overleaf-cep/services/web/test/frontend/shared/hooks/use-callback-handlers.test.js
Tim Down 7abafb01ea Merge pull request #23940 from overleaf/td-react-18
Upgrade to React 18

GitOrigin-RevId: 9b81936e6eea2bccd97fe5c2c5841f0b946371b8
2025-05-02 08:05:29 +00:00

34 lines
1 KiB
JavaScript

import sinon from 'sinon'
import { renderHook } from '@testing-library/react'
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)
})
})