civiccc / react-waypoint

A React component to execute a function whenever you scroll to an element.
MIT License
4.08k stars 208 forks source link

How do I test using Waypoint? #317

Closed mikecfisher closed 4 years ago

mikecfisher commented 5 years ago

I'm using this library a lot in a few apps, I haven't found a good example on how to test my components that use this. Say I want to simply write a test that asserts a specific function gets called when Waypoint scrolls into view. Are there any examples on the web I can look at?

p12y commented 5 years ago

I'd like to know this as well. At the moment, I'm calling the onChange method directly, like so:

act(() => {
      wrapper
        .find(Waypoint)
        .prop('onPositionChange')
        .call(null, { currentPosition: 'inside' });
    });

wrapper.update();
expect(/*something to happen*/);
pawelkrystkiewicz commented 4 years ago

I also would like to know how to test this

trotzig commented 4 years ago

The local test suite here could perhaps help? https://github.com/civiccc/react-waypoint/blob/master/test/waypoint_test.jsx

pawelkrystkiewicz commented 4 years ago

@trotzig thanks! This is a great reference. I was trying to avoid jasmine but I think I'll give in this time ;)

trotzig commented 4 years ago

I think you could do something similar with jest, mocha etc as well.