Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Samsonov committed Jul 27, 2018
1 parent f0e193a commit a33ebb7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 53 deletions.
70 changes: 24 additions & 46 deletions packages/debounce-handler/test/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ exports[`debounceHandler display name should wrap display name in non-production
exports[`debounceHandler should call \`e.persist()\` if it has been passed 1`] = `
Array [
Array [
[MockFunction] {
"calls": Array [
Array [],
],
"results": Array [
Object {
"isThrow": false,
"value": undefined,
},
],
Object {
"persist": [MockFunction] {
"calls": Array [
Array [],
],
"results": Array [
Object {
"isThrow": false,
"value": undefined,
},
],
},
},
undefined,
undefined,
],
]
`;
Expand All @@ -42,20 +42,20 @@ Array [
]
`;

exports[`debounceHandler should call actual handler during lifecycle 1`] = `Array []`;

exports[`debounceHandler should call actual handler during lifecycle 2`] = `
Array [
Array [
undefined,
],
]
`;

exports[`debounceHandler should pass \`delay\` option to \`just-debounce-it\` 1`] = `
Array [
Array [
[MockFunction] {
"calls": Array [
Array [],
],
"results": Array [
Object {
"isThrow": false,
"value": undefined,
},
],
},
[Function],
75,
undefined,
],
Expand All @@ -65,17 +65,7 @@ Array [
exports[`debounceHandler should pass \`leadingCall\` option to \`just-debounce-it\` 1`] = `
Array [
Array [
[MockFunction] {
"calls": Array [
Array [],
],
"results": Array [
Object {
"isThrow": false,
"value": undefined,
},
],
},
[Function],
75,
true,
],
Expand All @@ -85,18 +75,6 @@ Array [
exports[`debounceHandler should pass handler arguments through 1`] = `
Array [
Array [
[MockFunction] {
"calls": Array [
Array [],
],
"results": Array [
Object {
"isThrow": false,
"value": undefined,
},
],
},
undefined,
undefined,
],
]
Expand Down
26 changes: 19 additions & 7 deletions packages/debounce-handler/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('debounceHandler', () => {
let debounceHandler = null

beforeEach(() => {
mockJustDebounce = jest.fn(() => () => {})
mockJustDebounce = jest.fn(cb => cb)

jest.mock('just-debounce-it', () => mockJustDebounce)
jest.resetModules()
Expand All @@ -29,9 +29,24 @@ describe('debounceHandler', () => {
const testHandler = wrapper.find(Target).prop('testHandler')

testHandler()
mockTestHandler()

expect(mockJustDebounce.mock.calls).toMatchSnapshot()
expect(mockTestHandler.mock.calls).toMatchSnapshot()
})

it('should call actual handler during lifecycle', () => {
const EnhancedTarget = debounceHandler('testHandler')(Target)
const mockTestHandlerInitial = jest.fn()
const mockTestHandlerUpdated = jest.fn()
const wrapper = mount(
<EnhancedTarget testHandler={mockTestHandlerInitial} />
)
wrapper.setProps({testHandler: mockTestHandlerUpdated})
const testHandler = wrapper.find(Target).prop('testHandler')

testHandler()

expect(mockTestHandlerInitial.mock.calls).toMatchSnapshot()
expect(mockTestHandlerUpdated.mock.calls).toMatchSnapshot()
})

it('should call `e.persist()` if it has been passed', () => {
Expand All @@ -44,9 +59,8 @@ describe('debounceHandler', () => {
const testHandler = wrapper.find(Target).prop('testHandler')

testHandler({ persist: mockPersist })
mockTestHandler()

expect(mockJustDebounce.mock.calls).toMatchSnapshot()
expect(mockTestHandler.mock.calls).toMatchSnapshot()
expect(mockPersist.mock.calls).toMatchSnapshot()
})

Expand All @@ -59,7 +73,6 @@ describe('debounceHandler', () => {
const testHandler = wrapper.find(Target).prop('testHandler')

testHandler()
mockTestHandler()

expect(mockJustDebounce.mock.calls).toMatchSnapshot()
})
Expand All @@ -73,7 +86,6 @@ describe('debounceHandler', () => {
const testHandler = wrapper.find(Target).prop('testHandler')

testHandler()
mockTestHandler()

expect(mockJustDebounce.mock.calls).toMatchSnapshot()
})
Expand Down

0 comments on commit a33ebb7

Please sign in to comment.