Giter Club home page Giter Club logo

Comments (5)

Miteshdv avatar Miteshdv commented on June 13, 2024 3

ok i managed to get it work using combination of jest.useRealTimers(), setTimeout and done.

no jest.runAllTimers() / jest.useFakeTimers('modern')

simply do

it('i am testing', done => {
wrapper.find('button').prop('onClick')()
setTimeout(()=>{

done()
},600)
})

from use-debounce.

xnimorz avatar xnimorz commented on June 13, 2024 1

I've made an example of your case, everything seems to work properly.
Here is the code, I hope It would help you to determine the problem: https://github.com/xnimorz/use-debounce/compare/tmp?expand=1#diff-f2501e1cc67f3029fe72847a2b1dba6abfeabf59289997bcdb06eed7ca3d8b11R13

Please, check your config and whether or not jest.useFakeTimers('modern'); is used

from use-debounce.

xnimorz avatar xnimorz commented on June 13, 2024

Hi @Miteshdv
Thank you for the issue!

Could you provide some context, please?

At the moment we have https://github.com/xnimorz/use-debounce/blob/master/test/useDebouncedCallback.test.tsx for callback and https://github.com/xnimorz/use-debounce/blob/master/test/useDebounce.test.tsx for values.

You can find examples of testing components with these hooks inside these 2 files. The general piece of advice is to use stubs for timeouts and run them "to time" or run them all to test your components.

from use-debounce.

Miteshdv avatar Miteshdv commented on June 13, 2024

Thanks For Reply ,
I tried various ways , but i am getting error

ran 100000 timers, and there are still more! assuming we've hit an infinite recursion and bailing out

when i do jest.runAllTimers()

from use-debounce.

Miteshdv avatar Miteshdv commented on June 13, 2024

I have a component

const Time = ()=>{
debounced = useDebouncedCallback(()=>{
//CANT COVER THIS LINE IN TEST COVERAGE
console.log('test')
},500)

return <button onClick={debounced .callback}/>

}

i do

wrapper.find('button').prop('onClick')()

the callback function is not covered

i did

act(()=>{
jest.runAllTimers()})

i get error

from use-debounce.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.