Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upProvide testing/mocking instructions and export react-tracking/mock #134
Comments
|
Hi team, We've been integrating this wonderful package into our own application but have faced some issues with fixing broken unit tests as a result. We tried using the mock above to set the Here's an example:
When we move the EDIT: the prop-type warning was due to the mock using |
|
Hmm it may be because of the @track({ module: 'MyComponent' })
export class MyComponent extends Component {
render() {
...
}
}
const ConnectedMyComponent = connect(mapStateToProps)(MyComponent);
ConnectedMyComponent.propTypes = {
tracking: TrackingPropType,
};
ConnectedMyComponent.defaultProps = {
tracking: null,
};
export default ConnectedMyComponent;If not, maybe you could create a repro in Codesandbox or something? I can try and take a closer look when I get a chance. |
Hi, could you elaborate on the EDIT? What did you do to fix it? I'm newbie to react, just got a task to fix this problem. I also got a TypeError bug: Thanks a lot in advance! |
|
Hey @l225li are you still having this issue? Could you share more of your code or maybe create a Codesandbox example so I can take a closer look? |
|
With respect to the comment from @l225li, I also observed this issue recently when integrating For tracking implemented at the component level, a lot of the code looks like this...
The key for mocking, then, is to mock the default exported function ( By default, jest mocks do not support ES module semantics; when
This prevented me from mocking
Hope this helps. Aside: really love the work NYT team has done with this library. In recent years I have spent a lot of time working on Android (where NYT team also shines), and was very pleasantly surprised to find this library, which shares a core philosophy and solves foundational problems I encountered in past projects in the mobile space. Great job. |
|
Thank you @wokkaflokka , that's very helpful. And thank you for the kind words! |
I've been meaning to provide this as importable within react-tracking via something like:😁
import track, { mockTrackEvent, TrackingPropType } from 'react-tracking/mock';but haven't had a chance yet. PRs welcome!Originally posted by @tizmagik in #112 (comment)