Skip to content

Commit

Permalink
Merge pull request #580 from carloslancha/TestFixes
Browse files Browse the repository at this point in the history
Stub console.error | Fixes #579
  • Loading branch information
jbalsas authored Feb 20, 2018
2 parents fc3d60f + 7075fcb commit dbee0bc
Show file tree
Hide file tree
Showing 15 changed files with 255 additions and 27 deletions.
21 changes: 20 additions & 1 deletion packages/clay-alert/src/__tests__/ClayAlert.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import ClayAlert from '../ClayAlert';

let consoleErrorReference;
let alert;

const spritemap = '../node_modules/clay/lib/images/icons/icons.svg';

/**
* Stubs console.error
*/
function mockConsoleError() {
console.error = () => {};
}

describe('ClayAlert', function() {
beforeEach(() => {
consoleErrorReference = console.error;
});

afterEach(() => {
if (alert) {
alert.dispose();
}

console.error = consoleErrorReference;
});

it('should render default markup', function() {
Expand Down Expand Up @@ -128,6 +141,8 @@ describe('ClayAlert', function() {
});

it('should fail when no message is passed', function() {
mockConsoleError();

expect(() => {
alert = new ClayAlert({
spritemap: spritemap,
Expand All @@ -137,6 +152,8 @@ describe('ClayAlert', function() {
});

it('should fail when no spritemap is passed', function() {
mockConsoleError();

expect(() => {
alert = new ClayAlert({
message: 'message',
Expand All @@ -146,6 +163,8 @@ describe('ClayAlert', function() {
});

it('should fail when no title is passed', function() {
mockConsoleError();

expect(() => {
alert = new ClayAlert({
message: 'message',
Expand Down
21 changes: 20 additions & 1 deletion packages/clay-alert/src/__tests__/ClayStripe.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import ClayStripe from '../ClayStripe';

let consoleErrorReference;
let stripe;

const spritemap = '../node_modules/clay/lib/images/icons/icons.svg';

/**
* Stubs console.error
*/
function mockConsoleError() {
console.error = () => {};
}

describe('ClayStripe', function() {
beforeEach(() => {
consoleErrorReference = console.error;
});

afterEach(() => {
if (stripe) {
stripe.dispose();
}

console.error = consoleErrorReference;
});

it('should render default markup', function() {
Expand Down Expand Up @@ -150,6 +163,8 @@ describe('ClayStripe', function() {
});

it('should fail when no message is passed', function() {
mockConsoleError();

expect(() => {
stripe = new ClayStripe({
spritemap: spritemap,
Expand All @@ -159,6 +174,8 @@ describe('ClayStripe', function() {
});

it('should fail when no spritemap is passed', function() {
mockConsoleError();

expect(() => {
stripe = new ClayStripe({
message: 'message',
Expand All @@ -168,6 +185,8 @@ describe('ClayStripe', function() {
});

it('should fail when no title is passed', function() {
mockConsoleError();

expect(() => {
stripe = new ClayStripe({
message: 'message',
Expand Down
21 changes: 20 additions & 1 deletion packages/clay-alert/src/__tests__/ClayToast.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import ClayToast from '../ClayToast';

let consoleErrorReference;
let toast;

const spritemap = '../node_modules/clay/lib/images/icons/icons.svg';

/**
* Stubs console.error
*/
function mockConsoleError() {
console.error = () => {};
}

describe('ClayToast', function() {
beforeEach(() => {
consoleErrorReference = console.error;
});

afterEach(() => {
if (toast) {
toast.dispose();
}

console.error = consoleErrorReference;
});

it('should render default markup', function() {
Expand Down Expand Up @@ -150,6 +163,8 @@ describe('ClayToast', function() {
});

it('should fail when no message is passed', function() {
mockConsoleError();

expect(() => {
toast = new ClayToast({
spritemap: spritemap,
Expand All @@ -159,6 +174,8 @@ describe('ClayToast', function() {
});

it('should fail when no spritemap is passed', function() {
mockConsoleError();

expect(() => {
toast = new ClayToast({
message: 'message',
Expand All @@ -168,6 +185,8 @@ describe('ClayToast', function() {
});

it('should fail when no title is passed', function() {
mockConsoleError();

expect(() => {
toast = new ClayToast({
message: 'message',
Expand Down
4 changes: 2 additions & 2 deletions packages/clay-card-grid/src/__tests__/ClayCardGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ describe('ClayCardGrid', function() {
it('should render a ClayCardGrid with classes', () => {
component = new ClayCardGrid({
elementClasses: 'my-custom-class',
schema: [],
schema: {},
});

expect(component).toMatchSnapshot();
Expand All @@ -191,7 +191,7 @@ describe('ClayCardGrid', function() {
it('should render a ClayCardGrid with id', () => {
component = new ClayCardGrid({
id: 'myId',
schema: [],
schema: {},
});

expect(component).toMatchSnapshot();
Expand Down
18 changes: 18 additions & 0 deletions packages/clay-card/src/__tests__/ClayFileCard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ClayFileCard from '../ClayFileCard';

let component;
let consoleErrorReference;
let spritemap = 'icons.svg';
let actionItems = [
{
Expand All @@ -13,11 +14,24 @@ let actionItems = [
},
];

/**
* Stubs console.error
*/
function mockConsoleError() {
console.error = () => {};
}

describe('ClayFileCard', function() {
beforeEach(() => {
consoleErrorReference = console.error;
});

afterEach(() => {
if (component) {
component.dispose();
}

console.error = consoleErrorReference;
});

it('should render the default markup', () => {
Expand Down Expand Up @@ -395,6 +409,8 @@ describe('ClayFileCard', function() {
});

it('should fail when no spritemap is passed', function() {
mockConsoleError();

expect(() => {
component = new ClayFileCard({
title: 'My Title',
Expand All @@ -403,6 +419,8 @@ describe('ClayFileCard', function() {
});

it('should fail when no title is passed', function() {
mockConsoleError();

expect(() => {
component = new ClayFileCard({
spritemap: spritemap,
Expand Down
18 changes: 18 additions & 0 deletions packages/clay-card/src/__tests__/ClayHorizontalCard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ClayHorizontalCard from '../ClayHorizontalCard';

let component;
let consoleErrorReference;
let spritemap = 'icons.svg';
let actionItems = [
{
Expand All @@ -13,11 +14,24 @@ let actionItems = [
},
];

/**
* Stubs console.error
*/
function mockConsoleError() {
console.error = () => {};
}

describe('ClayHorizontalCard', function() {
beforeEach(() => {
consoleErrorReference = console.error;
});

afterEach(() => {
if (component) {
component.dispose();
}

console.error = consoleErrorReference;
});

it('should render the default markup', () => {
Expand Down Expand Up @@ -149,6 +163,8 @@ describe('ClayHorizontalCard', function() {
});

it('should fail when no spritemap is passed', function() {
mockConsoleError();

expect(() => {
component = new ClayHorizontalCard({
title: 'My Title',
Expand All @@ -157,6 +173,8 @@ describe('ClayHorizontalCard', function() {
});

it('should fail when no title is passed', function() {
mockConsoleError();

expect(() => {
component = new ClayHorizontalCard({
spritemap: spritemap,
Expand Down
16 changes: 16 additions & 0 deletions packages/clay-card/src/__tests__/ClayImageCard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ClayImageCard from '../ClayImageCard';

let component;
let consoleErrorReference;
let spritemap = 'icons.svg';
let actionItems = [
{
Expand All @@ -13,11 +14,24 @@ let actionItems = [
},
];

/**
* Stubs console.error
*/
function mockConsoleError() {
console.error = () => {};
}

describe('ClayImageCard', function() {
beforeEach(() => {
consoleErrorReference = console.error;
});

afterEach(() => {
if (component) {
component.dispose();
}

console.error = consoleErrorReference;
});

it('should render the default markup', () => {
Expand Down Expand Up @@ -415,6 +429,8 @@ describe('ClayImageCard', function() {
});

it('should fail when no title is passed', function() {
mockConsoleError();

expect(() => {
component = new ClayImageCard();
}).toThrow();
Expand Down
16 changes: 16 additions & 0 deletions packages/clay-card/src/__tests__/ClayUserCard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ClayUserCard from '../ClayUserCard';

let component;
let consoleErrorReference;
let spritemap = 'icons.svg';
let actionItems = [
{
Expand All @@ -13,11 +14,24 @@ let actionItems = [
},
];

/**
* Stubs console.error
*/
function mockConsoleError() {
console.error = () => {};
}

describe('ClayUserCard', function() {
beforeEach(() => {
consoleErrorReference = console.error;
});

afterEach(() => {
if (component) {
component.dispose();
}

console.error = consoleErrorReference;
});

it('should render the default markup', () => {
Expand Down Expand Up @@ -267,6 +281,8 @@ describe('ClayUserCard', function() {
});

it('should fail when no name is passed', function() {
mockConsoleError();

expect(() => {
component = new ClayUserCard();
}).toThrow();
Expand Down
Loading

0 comments on commit dbee0bc

Please sign in to comment.