Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

Commit

Permalink
mock lodash in file
Browse files Browse the repository at this point in the history
  • Loading branch information
silviuaavram committed Jan 7, 2020
1 parent b5c06f7 commit c803d83
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 48 deletions.
19 changes: 19 additions & 0 deletions packages/react/test/__mocks__/lodash.ts
@@ -0,0 +1,19 @@
// @ts-ignore
export * from 'lodash'
export const debounce = (fn: Function, time: number): Function => {
let timeoutId
function cancel() {
if (timeoutId) {
clearTimeout(timeoutId)
}
}
function wrapper(...args) {
cancel()
timeoutId = setTimeout(() => {
timeoutId = null
fn(...args)
}, time)
}
wrapper.cancel = cancel
return wrapper
}
24 changes: 0 additions & 24 deletions packages/react/test/specs/components/Carousel/Carousel-test.tsx
Expand Up @@ -56,30 +56,6 @@ const getItemAtIndexWrapper = (wrapper: ReactWrapper, index: number): CommonWrap
findIntrinsicElement(wrapper, `.${CarouselItem.className}`).at(index)

jest.useFakeTimers()
jest.mock('lodash', () => ({
...jest.requireActual('lodash'),
debounce: (fn: Function, time: number): Function => {
let timeoutId

function cancel() {
if (timeoutId) {
clearTimeout(timeoutId)
}
}

function wrapper(...args) {
cancel()
timeoutId = setTimeout(() => {
timeoutId = null
fn(...args)
}, time)
}

wrapper.cancel = cancel

return wrapper
},
}))

describe('Carousel', () => {
isConformant(Carousel)
Expand Down
25 changes: 1 addition & 24 deletions packages/react/test/specs/components/Dropdown/Dropdown-test.tsx
Expand Up @@ -13,30 +13,7 @@ import { ShorthandValue } from 'src/types'

jest.dontMock('keyboard-key')
jest.useFakeTimers()
jest.mock('lodash', () => ({
...jest.requireActual('lodash'),
debounce: (fn: Function, time: number): Function => {
let timeoutId

function cancel() {
if (timeoutId) {
clearTimeout(timeoutId)
}
}

function wrapper(...args) {
cancel()
timeoutId = setTimeout(() => {
timeoutId = null
fn(...args)
}, time)
}

wrapper.cancel = cancel

return wrapper
},
}))
// jest.mock('lodash')

const getTriggerButtonWrapper = (wrapper: ReactWrapper): CommonWrapper =>
findIntrinsicElement(wrapper, `.${Dropdown.slotClassNames.triggerButton}`)
Expand Down

0 comments on commit c803d83

Please sign in to comment.