-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#317: Refactored hooks, complete tests
- Loading branch information
Showing
5 changed files
with
55 additions
and
22 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react'; | ||
import {mount} from 'enzyme/build'; | ||
import {useAnalytics} from '../hooks'; | ||
|
||
describe('Google Analytics hooks test suite', () => { | ||
describe('useAnaltyics', () => { | ||
let PlaceHolder; | ||
beforeEach(() => { | ||
delete window.dataLayer; | ||
delete window.gtag; | ||
PlaceHolder = ({updatableProperty = ''}) => { | ||
useAnalytics(); | ||
return (<span>{updatableProperty}</span>); | ||
}; | ||
}); | ||
test('componentDidMount, should load script and add helper functions', () => { | ||
// Given | ||
window.isotopeConfiguration = {googleAnalyticsTrackingId: 'UA-1337-33'}; | ||
// When | ||
mount(<PlaceHolder />); | ||
// Then | ||
expect(window.gtag).toBeInstanceOf(Function); | ||
expect(window.dataLayer).toHaveLength(2); | ||
expect(window.dataLayer.map(args => [...args])).toEqual([ | ||
['js', expect.any(Date)], | ||
['config', 'UA-1337-33', {page_path: '/'}] | ||
]); | ||
}); | ||
test('componentDidUpdate, should update page location', () => { | ||
// Given | ||
window.isotopeConfiguration = {googleAnalyticsTrackingId: 'UA-1337-33'}; | ||
const rendered = mount(<PlaceHolder updatableProperty="First Pass" />); | ||
// When | ||
rendered.setProps({updatableProperty: 'Second Pass'}); | ||
// Then | ||
expect(window.gtag).toBeInstanceOf(Function); | ||
expect(window.dataLayer).toHaveLength(3); | ||
expect(window.dataLayer.map(args => [...args])).toEqual([ | ||
['js', expect.any(Date)], | ||
['config', 'UA-1337-33', {page_path: '/'}], | ||
['config', 'UA-1337-33', {page_path: '/'}] | ||
]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export { | ||
useAnalytics, | ||
updateAnalytics | ||
useAnalytics | ||
} from './hooks'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters