Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/create unit tests #9

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Create some unit tests for the component
  • Loading branch information
Luke Pettway committed Aug 9, 2017
commit f1ad99426fc9e88a9d6f33a324b4d36ff4321381
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"start": "webpack-dev-server --inline --hot --host 127.0.0.1 --content-base examples/",
"build": "rimraf dist && mkdirp dist && babel src -d dist",
"test": "echo \"Error: no test specified\" && exit 1",
"test": "jest",
"prepublish": "npm run build"
},
"files": [
Expand All @@ -31,13 +31,18 @@
"babel": "^6.23.0",
"babel-cli": "^6.24.1",
"babel-core": "^6.24.1",
"babel-jest": "^20.0.3",
"babel-loader": "^7.1.1",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"webpack": "^3.0.0",
"webpack-dev-server": "^2.5.0",
"enzyme": "^2.9.1",
"jest": "^20.0.4",
"mkdirp": "^0.5.1",
"rimraf": "^2.6.1"
"react-axe": "^2.1.7",
"react-test-renderer": "^15.6.1",
"rimraf": "^2.6.1",
"webpack": "^3.0.0",
"webpack-dev-server": "^2.5.0"
}
}
28 changes: 28 additions & 0 deletions src/Announcer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import Announcer from './Announcer';
import renderer from 'react-test-renderer';
import { shallow } from 'enzyme';

test('Component is created', () => {
const wrapper = renderer.create(
<Announcer text="This is an announcement!" />
);
let tree = wrapper.toJSON();
expect(tree).toMatchSnapshot();
});

test('Should have a default politeness prop of `polite`', () => {
const wrapper = shallow(<Announcer text="" />);
const politeness = wrapper.instance().props.politeness;
expect(politeness).toBe('polite');
});

test('Text node updates when state changes', () => {
// Since we really can't test the live announcement,
// we can at least ensure the text node gets updated.
const wrapper = shallow(<Announcer text="" />);
const testAnnouncementStr = 'Here\'s a new announcement!';
expect(wrapper.text()).toEqual('');
wrapper.setProps({ text: testAnnouncementStr });
expect(wrapper.text()).toEqual(testAnnouncementStr);
});
28 changes: 28 additions & 0 deletions src/__snapshots__/Announcer.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Component is created 1`] = `
<div
aria-live="polite"
className={undefined}
style={
Object {
"border": "0",
"clip": "rect(0px, 0px, 0px, 0px)",
"clipPath": "polygon(0px 0px, 0px 0px, 0px 0px, 0px 0px)",
"display": "block",
"height": "1px",
"margin": "-1px",
"overflow": "hidden",
"padding": "0",
"position": "absolute",
"visibility": "visible",
"whiteSpace": "nowrap",
"width": "1px",
}
}
>
<p>
This is an announcement!
</p>
</div>
`;