davidguttman / react-pivot

React-Pivot is a data-grid component with pivot-table-like functionality for data display, filtering, and exploration.
http://davidguttman.github.io/react-pivot/
1.05k stars 148 forks source link

refactor: export download csv function as an object #101

Closed placide-irandora-interlincx closed 2 years ago

placide-irandora-interlincx commented 2 years ago

CONTEXT

This PR refactors the download CSV function to be exported as an object: { download: function (params) {code...} }. This will facilitate in unit testing when we want to stub the functionality of the download function.

In my scenario, we are using Sinon for stubbing and mocking. The Sinon method - sinon.stub(object, "method") requires a root object and a property to stub on that object. Thus, we could not successfully stub the function since It is currently exported as a function not an object.

placide-irandora-interlincx commented 2 years ago

Found out a way to mock the function with proxyquire.