Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Skerritt committed Nov 27, 2018
1 parent 9d92e35 commit 4f20107
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
18 changes: 7 additions & 11 deletions src/__tests__/Ads-test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import React from 'react';
import { shallow } from 'enzyme';
import { mount } from 'enzyme';
import Helmet from 'react-helmet';
import Ads from '../lib/Ads';

describe('Ads', () => {
test('exists and is not null', () => {
const element = shallow(<Ads />);
const element = mount(<Ads />);
expect(element.exists()).toBe(true);
expect(element.getElement()).not.toBe(null);
});

test('returns ad scripts even when no ad slots are defined', () => {
const element = shallow(<Ads />);
expect(element.find('script').length).toBe(2);
});

test('contains ad slot scripts when given', () => {
const slots = [
{
Expand All @@ -24,10 +20,10 @@ describe('Ads', () => {
elementId: 'testAd'
}
];
const element = shallow(<Ads slots={slots} />);
const slotScriptEl = element.find('script').at(1);
expect(slotScriptEl.html()).toMatch(
mount(<Ads slots={slots} />);
const helmet = Helmet.peek();
expect(helmet.scriptTags.some(tag => tag.innerHTML.indexOf(
`googletag.defineSlot('/123456/Test_100x100', [100, 100], 'testAd').addService(googletag.pubads());`
);
) > -1)).toBe(true);
});
});
10 changes: 6 additions & 4 deletions src/__tests__/Gtm-test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import React from 'react';
import { shallow } from 'enzyme';
import { mount } from 'enzyme';
import Helmet from 'react-helmet';
import Gtm from '../lib/Gtm';

describe('Gtm', () => {
test('exists and is not null', () => {
const element = shallow(<Gtm />);
const element = mount(<Gtm />);
expect(element.exists()).toBe(true);
expect(element.getElement()).not.toBe(null);
});

test('contains containerId', () => {
const element = shallow(<Gtm containerId="test12345" />);
expect(element.html()).toMatch(`test12345`);
mount(<Gtm containerId="test12345" />);
const helmet = Helmet.peek();
expect(helmet.scriptTags.some(tag => tag.innerHTML.indexOf(`test12345`) > -1)).toBe(true);
});
});
10 changes: 6 additions & 4 deletions src/__tests__/Vwo-test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import React from 'react';
import { shallow } from 'enzyme';
import { mount } from 'enzyme';
import Helmet from 'react-helmet';
import Vwo from '../lib/Vwo';

describe('Vwo', () => {
test('exists and is not null', () => {
const element = shallow(<Vwo />);
const element = mount(<Vwo />);
expect(element.exists()).toBe(true);
expect(element.getElement()).not.toBe(null);
});

test('contains accountId', () => {
const element = shallow(<Vwo accountId="test12345" />);
expect(element.html()).toMatch(`test12345`);
mount(<Vwo accountId="test12345" />);
const helmet = Helmet.peek();
expect(helmet.scriptTags.some(tag => tag.innerHTML.indexOf(`test12345`) > -1)).toBe(true);
});
});
8 changes: 5 additions & 3 deletions src/__tests__/WebFont-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { shallow } from 'enzyme';
import { shallow, mount } from 'enzyme';
import Helmet from 'react-helmet';
import WebFont from '../lib/WebFont';

describe('WebFont', () => {
Expand All @@ -9,7 +10,7 @@ describe('WebFont', () => {
});

test('contains font family strings', () => {
const element = shallow(
mount(
<WebFont
families={[
{
Expand All @@ -19,6 +20,7 @@ describe('WebFont', () => {
]}
/>
);
expect(element.html()).toMatch(`["Roboto:300,500,700"]`);
const helmet = Helmet.peek();
expect(helmet.scriptTags.some(tag => tag.innerHTML.indexOf(`["Roboto:300,500,700"]`) > -1)).toBe(true);
});
});

0 comments on commit 4f20107

Please sign in to comment.