-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gatsby-plugin-google-tagmanager): allow functions for defaultData…
…Layer option (#27886) * Added check for function type for defaultDataLayer prop * Fixing lint issues * More lint fixes * Add tests Co-authored-by: Max Stoiber <contact@mxstbr.com>
- Loading branch information
1 parent
5bc1134
commit 631f3c4
Showing
3 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
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
35 changes: 35 additions & 0 deletions
35
packages/gatsby-plugin-google-tagmanager/src/__tests__/gatsby-node.js
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,35 @@ | ||
import { pluginOptionsSchema } from "../gatsby-node" | ||
import { testPluginOptionsSchema } from "gatsby-plugin-utils" | ||
|
||
describe(`pluginOptionsSchema`, () => { | ||
it(`should validate valid options`, async () => { | ||
const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, { | ||
id: `YOUR_GOOGLE_TAGMANAGER_ID`, | ||
includeInDevelopment: false, | ||
defaultDataLayer: { platform: `gatsby` }, | ||
gtmAuth: `YOUR_GOOGLE_TAGMANAGER_ENVIRONMENT_AUTH_STRING`, | ||
gtmPreview: `YOUR_GOOGLE_TAGMANAGER_ENVIRONMENT_PREVIEW_NAME`, | ||
dataLayerName: `YOUR_DATA_LAYER_NAME`, | ||
routeChangeEventName: `YOUR_ROUTE_CHANGE_EVENT_NAME`, | ||
}) | ||
|
||
expect(isValid).toEqual(true) | ||
}) | ||
|
||
it(`should support defaultDataLayer as a function`, async () => { | ||
const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, { | ||
defaultDataLayer: () => { | ||
return { | ||
originalLocation: | ||
document.location.protocol + | ||
`//` + | ||
document.location.hostname + | ||
document.location.pathname + | ||
document.location.search, | ||
} | ||
}, | ||
}) | ||
|
||
expect(isValid).toEqual(true) | ||
}) | ||
}) |
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