diff --git a/src/__tests__/e2e.test.js b/src/__tests__/e2e.test.js index 1bef9d8..f68f122 100644 --- a/src/__tests__/e2e.test.js +++ b/src/__tests__/e2e.test.js @@ -1,3 +1,4 @@ +// @ts-check /* eslint-disable react/destructuring-assignment,react/no-multi-comp,react/prop-types,react/prefer-stateless-function */ /* eslint-disable jsx-a11y/control-has-associated-label */ /* eslint-disable global-require */ @@ -941,6 +942,49 @@ const runTests = useBuiltLib => { expect(parent.instance().child).not.toBeNull(); expect(focusFn).toHaveBeenCalledTimes(1); }); + + it('can establish tracking context with only hooks', () => { + function MyButton() { + const { trackEvent } = useTracking({ element: 'MyButton' }); + return ( + + ); + } + + function App() { + const { Track } = useTracking( + { page: 'App' }, + { dispatch, dispatchOnMount: true } + ); + return ( + + + + ); + } + + const wrappedApp = mount(); + wrappedApp.find('button').simulate('click'); + + expect(dispatch).toHaveBeenCalledTimes(2); + // dispatch on mount + expect(dispatch).toHaveBeenCalledWith({ + page: 'App', + }); + // simulated button click + expect(dispatch).toHaveBeenCalledWith({ + page: 'App', + event: 'buttonClick', + element: 'MyButton', + }); + }); }; describe('e2e', () => { diff --git a/tsconfig.json b/tsconfig.json index 4f8aba6..afa55c8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,8 @@ { "compilerOptions": { "experimentalDecorators": true, - "allowJs": true + "allowJs": true, + "jsx": "react-jsx" }, "exclude": ["node_modules"] }