Skip to content
This repository was archived by the owner on Dec 24, 2019. It is now read-only.

Commit 5fafe1e

Browse files
author
Patrick Burtchaell
authored
Merge pull request #131 from terenced/master
Allow notification title to be a React element.
2 parents 88a4189 + 3d7d429 commit 5fafe1e

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/defaultPropTypes.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,8 @@ export default {
2424
className: PropTypes.string,
2525
activeClassName: PropTypes.string,
2626
isActive: PropTypes.bool,
27-
title: PropTypes.string
27+
title: PropTypes.oneOfType([
28+
PropTypes.string,
29+
PropTypes.node
30+
])
2831
};

test/notification.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import sinon from 'sinon';
23
import { Notification } from '../src/index';
34
import mockNotification from './mockNotification';
45

@@ -28,6 +29,39 @@ describe('<Notification />', () => {
2829
const action = wrapper.find(actionClassName);
2930
const title = wrapper.find(titleClassName);
3031

32+
describe('title as React.PropTypes.node', () => {
33+
before(() => {
34+
// Since react will console.error propType warnings,
35+
// we stub console.error to raise an error
36+
// so the test runner will pick it up.
37+
sinon.stub(console, 'error').callsFake((warning) => {
38+
throw new Error(warning);
39+
});
40+
});
41+
42+
after(() => {
43+
/* eslint-disable no-console */
44+
console.error.restore();
45+
/* eslint-enable no-console */
46+
});
47+
48+
it('renders without error', () => {
49+
const icon = <i aria-hidden="true" className="warning" />;
50+
shallow(
51+
<Notification
52+
message={mockNotification.message}
53+
action={mockNotification.action}
54+
barStyle={mockNotification.barStyle}
55+
actionStyle={mockNotification.actionStyle}
56+
activeBarStyle={mockNotification.activeBarStyle}
57+
onClick={mockNotification.onClick}
58+
dismissAfter={mockNotification.dismissAfter}
59+
title={icon}
60+
/>
61+
);
62+
});
63+
});
64+
3165
it('has the className `notification-bar`', () => {
3266
expect(component).to.have.className('notification-bar');
3367
});

0 commit comments

Comments
 (0)