Skip to content

Commit

Permalink
feat: remove middleware helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
macoley committed Apr 11, 2022
1 parent 6f5debb commit 87d93d9
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 68 deletions.
55 changes: 0 additions & 55 deletions src/__test__/events.test.tsx → src/__tests__/events.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as React from 'react'
import { fireEvent, render } from '@testing-library/react'
import events from '../events'
import { act } from 'react-dom/test-utils'
import { withDefault, withNothing, withPayload } from '../consts'

// Counter Component
const Counter = ({ role }: { role: string }) => {
Expand Down Expand Up @@ -282,57 +281,3 @@ test('Static usage', () => {
expect(staticAliceListener).toBeCalledTimes(2)
expect(staticBobListener).toBeCalledTimes(1) // should not changed
})

test('Basic usage', () => {
const withPayloadListener = jest.fn()
const withNothingListener = jest.fn()
const withDefaultListener = jest.fn()

const [Provider, , staticEvent] = events({
withPayload: withPayload<{ alice: string; bob: number }>(),
withNothing: withNothing,
withDefault: withDefault({ alice: 'alice', bob: 100 })
})

const App = () => (
<Provider>
<Counter role='counter' />
</Provider>
)

render(<App />)

staticEvent.subscribe({
withPayload: withPayloadListener,
withNothing: withNothingListener,
withDefault: withDefaultListener
})

expect(withPayloadListener).toBeCalledTimes(0)
expect(withNothingListener).toBeCalledTimes(0)
expect(withDefaultListener).toBeCalledTimes(0)

act(() => {
staticEvent.dispatch('withPayload', { alice: 'alice', bob: 100 })
})
expect(withPayloadListener).toBeCalledTimes(1)
expect(withPayloadListener).toBeCalledWith({ alice: 'alice', bob: 100 })
expect(withNothingListener).toBeCalledTimes(0)
expect(withDefaultListener).toBeCalledTimes(0)

act(() => {
staticEvent.dispatch('withNothing')
})
expect(withPayloadListener).toBeCalledTimes(1)
expect(withNothingListener).toBeCalledTimes(1)
expect(withNothingListener).toBeCalledWith(undefined)
expect(withDefaultListener).toBeCalledTimes(0)

act(() => {
staticEvent.dispatch('withDefault', { bob: 200 })
})
expect(withPayloadListener).toBeCalledTimes(1)
expect(withNothingListener).toBeCalledTimes(1)
expect(withDefaultListener).toBeCalledTimes(1)
expect(withDefaultListener).toBeCalledWith({ alice: 'alice', bob: 200 })
})
12 changes: 0 additions & 12 deletions src/consts.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { default as events } from './events'
export { withPayload, withDefault, withNothing } from './consts'

0 comments on commit 87d93d9

Please sign in to comment.