Skip to content

Commit

Permalink
Add tests and coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
alinemorelliw committed Jun 18, 2017
1 parent 41ce016 commit b11bfac
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .eslintignore
@@ -1 +1,3 @@
node_modules
node_modules
__tests__
coverage
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,2 +1,3 @@
node_modules
*.log
*.log
coverage
7 changes: 5 additions & 2 deletions package.json
Expand Up @@ -44,9 +44,12 @@
"enzyme": "^2.8.2",
"eslint": "^3.9.0",
"jest": "^19.0.2",
"react": "^15.5.0"
"react": "^15.5.0",
"react-addons-test-utils": "^15.0.1",
"react-dom": "^15.0.1"
},
"jest": {
"testRegex": "__tests__.*\\.spec.js$"
"testRegex": "__tests__.*\\.spec.js$",
"collectCoverage": true
}
}
22 changes: 22 additions & 0 deletions src/__tests__/Snippets.spec.js
@@ -0,0 +1,22 @@
import Snippets from '../Snippets'

let args
let snippets

describe('Snippets', () => {
beforeEach(() => {
args = { id: 'GTM-abc123', dataLayerName: 'dataLayer', additionalEvents: {} }
snippets = Snippets(args)
})

it('should use the `id` for the iframe', () => {
expect(snippets.iframe).toContain('id=GTM-abc123', 1)
})

it('no id provided should log a warn', () => {
console.warn = jest.fn()
const noIdArgs = { dataLayerName: 'dataLayer', additionalEvents: {} }
Snippets(noIdArgs)
expect(console.warn).toBeCalled()
})
})
20 changes: 20 additions & 0 deletions src/__tests__/TagManager.spec.js
@@ -0,0 +1,20 @@
import React from 'react'
import { mount } from 'enzyme'
import TagManager from '../TagManager'

describe('TagManager', () => {
it('should render tagmanager', () => {
const wrapper = mount(
<TagManager gtmId='GTM-abc123' />
)
expect(wrapper.find('noscript')).toHaveLength(1)
})

it('should render datalayer', () => {
const dataLayer = {}
const wrapper = mount(
<TagManager gtmId='GTM-abc123' dataLayer={dataLayer} />
)
expect(wrapper.find('noscript')).toHaveLength(1)
})
})
11 changes: 11 additions & 0 deletions src/__tests__/warn.spec.js
@@ -0,0 +1,11 @@
import sinon from 'sinon'
import warn from '../utils/warn'

describe('warn()', function () {
it('should append [react-gtm] to warning messages', () => {
sinon.stub(console, 'warn')
// // console.warn.toHaveBeenCalled()
warn('foo')
console.warn.toHaveBeenCalled
})
})
50 changes: 48 additions & 2 deletions yarn.lock
Expand Up @@ -967,7 +967,7 @@ core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"

create-react-class@^15.5.2, create-react-class@^15.6.0:
create-react-class@^15.6.0:
version "15.6.0"
resolved "https://registry.yarnpkg.com/create-react-class/-/create-react-class-15.6.0.tgz#ab448497c26566e1e29413e883207d57cfe7bed4"
dependencies:
Expand Down Expand Up @@ -1486,6 +1486,12 @@ form-data@~2.1.1:
combined-stream "^1.0.5"
mime-types "^2.1.12"

formatio@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/formatio/-/formatio-1.1.1.tgz#5ed3ccd636551097383465d996199100e86161e9"
dependencies:
samsam "~1.1"

fs-readdir-recursive@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs-readdir-recursive/-/fs-readdir-recursive-1.0.0.tgz#8cd1745c8b4f8a29c8caec392476921ba195f560"
Expand Down Expand Up @@ -1727,6 +1733,10 @@ inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.0, inherits@~2.0.1:
version "2.0.3"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"

inherits@2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.1.tgz#b17d08d326b4423e568eff719f91b0b1cbdf69f1"

ini@~1.3.0:
version "1.3.4"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.4.tgz#0537cb79daf59b59a1a517dff706c86ec039162e"
Expand Down Expand Up @@ -2392,6 +2402,10 @@ lodash@^4.0.0, lodash@^4.14.0, lodash@^4.17.2, lodash@^4.2.0, lodash@^4.3.0:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"

lolex@1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/lolex/-/lolex-1.3.2.tgz#7c3da62ffcb30f0f5a80a2566ca24e45d8a01f31"

longest@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
Expand Down Expand Up @@ -2774,7 +2788,7 @@ promise@^7.1.1:
dependencies:
asap "~2.0.3"

prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.6:
prop-types@^15.5.10, prop-types@^15.5.4:
version "15.5.10"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.5.10.tgz#2797dfc3126182e3a95e3dfbb2e893ddd7456154"
dependencies:
Expand Down Expand Up @@ -2809,6 +2823,19 @@ rc@^1.1.7:
minimist "^1.2.0"
strip-json-comments "~2.0.1"

react-addons-test-utils@^15.0.1:
version "15.6.0"
resolved "https://registry.yarnpkg.com/react-addons-test-utils/-/react-addons-test-utils-15.6.0.tgz#062d36117fe8d18f3ba5e06eb33383b0b85ea5b9"

react-dom@^15.0.1:
version "15.6.1"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-15.6.1.tgz#2cb0ed4191038e53c209eb3a79a23e2a4cf99470"
dependencies:
fbjs "^0.8.9"
loose-envify "^1.1.0"
object-assign "^4.1.0"
prop-types "^15.5.10"

react@^15.5.0:
version "15.6.1"
resolved "https://registry.yarnpkg.com/react/-/react-15.6.1.tgz#baa8434ec6780bde997cdc380b79cd33b96393df"
Expand Down Expand Up @@ -3017,6 +3044,10 @@ safe-buffer@^5.0.1, safe-buffer@~5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.0.1.tgz#d263ca54696cd8a306b5ca6551e92de57918fbe7"

samsam@1.1.2, samsam@~1.1:
version "1.1.2"
resolved "https://registry.yarnpkg.com/samsam/-/samsam-1.1.2.tgz#bec11fdc83a9fda063401210e40176c3024d1567"

sane@~1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/sane/-/sane-1.5.0.tgz#a4adeae764d048621ecb27d5f9ecf513101939f3"
Expand Down Expand Up @@ -3065,6 +3096,15 @@ signal-exit@^3.0.0:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"

sinon@^1.14.1:
version "1.17.7"
resolved "https://registry.yarnpkg.com/sinon/-/sinon-1.17.7.tgz#4542a4f49ba0c45c05eb2e9dd9d203e2b8efe0bf"
dependencies:
formatio "1.1.1"
lolex "1.3.2"
samsam "1.1.2"
util ">=0.10.3 <1"

slash@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55"
Expand Down Expand Up @@ -3333,6 +3373,12 @@ util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"

"util@>=0.10.3 <1":
version "0.10.3"
resolved "https://registry.yarnpkg.com/util/-/util-0.10.3.tgz#7afb1afe50805246489e3db7fe0ed379336ac0f9"
dependencies:
inherits "2.0.1"

uuid@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a"
Expand Down

0 comments on commit b11bfac

Please sign in to comment.