Skip to content

Commit

Permalink
adding jest and a few simple tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luisrudge committed Jan 12, 2017
1 parent 420714f commit acc4481
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
coverage/
build/
css/index.css
lib/
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ node_js:
- '4.2'
script:
- 'npm run test:cli'
- 'npm run test:jest'
env:
- CXX=g++-4.8
sudo: false
Expand Down
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"test:browser": "zuul --local 8080 --disable-tunnel -- test/**/*.test.js",
"test:cli": "mochify --extension=.jsx --transform=babelify test/**/*.test.js",
"test:watch": "mochify --watch --extension=.jsx --transform=babelify test/**/*.test.js",
"test:jest": "jest --coverage",
"test:jest:watch": "jest --watchAll --coverage",
"publish:cdn": "ccu",
"release": "scripts/release.sh"
},
Expand All @@ -46,6 +48,7 @@
"bump-version": "^0.5.0",
"component-cdn-uploader": "auth0/component-cdn-uploader#1.1.0",
"css-loader": "^0.25.0",
"enzyme": "2.7.0",
"eslint": "3.7.1",
"eslint-config-auth0-base": "6.0.0",
"eslint-plugin-import": "1.16.0",
Expand All @@ -59,8 +62,10 @@
"grunt-env": "^0.4.4",
"grunt-exec": "^0.4.6",
"grunt-webpack": "^1.0.18",
"jest": "18.1.0",
"mochify": "^2.12.0",
"react-addons-test-utils": "^15.0.0 || ^16.0.0",
"react-test-renderer": "15.4.2",
"semver": "^5.3.0",
"sinon": "^1.15.4",
"smart-banner-webpack-plugin": "^2.0.0",
Expand Down Expand Up @@ -97,5 +102,26 @@
"mainBundleFile": "lock.min.js",
"bucket": "assets.us.auth0.com",
"localPath": "build"
},
"jest": {
"modulePaths": [
"<rootDir>/src/"
],
"coveragePathIgnorePatterns": [
"/node_modules/",
"<rootDir>/test/",
"<rootDir>/lib/",
"<rootDir>/src/__tests__/testUtils.js"
],
"testPathIgnorePatterns": [
"/node_modules/",
"<rootDir>/test/",
"<rootDir>/lib/",
"<rootDir>/src/__tests__/testUtils.js"
],
"coverageReporters": [
"lcov",
"text-summary"
]
}
}
68 changes: 68 additions & 0 deletions src/__tests__/__snapshots__/auth_button.test.jsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
exports[`AuthButton renders correctly 1`] = `
<button
className="auth0-lock-social-button auth0-lock-social-big-button"
data-provider="strategy"
disabled={false}
onClick={[Function]}
style={Object {}}
type="button">
<div
className="auth0-lock-social-button-icon"
style={Object {}} />
<div
className="auth0-lock-social-button-text"
style={Object {}}>
label
</div>
</button>
`;

exports[`AuthButton renders when \`big\` is false 1`] = `
<button
className="auth0-lock-social-button"
data-provider="strategy"
disabled={false}
onClick={[Function]}
style={Object {}}
type="button">
<div
className="auth0-lock-social-button-icon"
style={Object {}} />
<div
className="auth0-lock-social-button-text"
style={Object {}}>
label
</div>
</button>
`;

exports[`AuthButton renders with style customizations 1`] = `
<button
className="auth0-lock-social-button auth0-lock-social-big-button"
data-provider="strategy"
disabled={false}
onClick={[Function]}
style={
Object {
"backgroundColor": "primaryColor",
}
}
type="button">
<div
className="auth0-lock-social-button-icon"
style={
Object {
"backgroundImage": "url(\'test\')",
}
} />
<div
className="auth0-lock-social-button-text"
style={
Object {
"color": "foregroundColor",
}
}>
label
</div>
</button>
`;
43 changes: 43 additions & 0 deletions src/__tests__/auth_button.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react';
import { mount } from 'enzyme';

import { expectComponent, noop } from './testUtils'

import AuthButton from 'ui/button/auth_button';

describe('AuthButton', () => {
const defaultProps = {
label: 'label',
onClick: noop,
strategy: 'strategy'
};
it('renders correctly', () => {
expectComponent(
<AuthButton {...defaultProps} />
).toMatchSnapshot();
});
it('renders with style customizations', () => {
expectComponent(
<AuthButton
{...defaultProps}
icon="test"
primaryColor="primaryColor"
foregroundColor="foregroundColor"
/>
).toMatchSnapshot();
});
it('renders when `big` is false', () => {
expectComponent(
<AuthButton
{...defaultProps}
isBig={false}
/>
).toMatchSnapshot();
});
it('should trigger onClick when clicked', () => {
const onClick = jest.fn();
const wrapper = mount(<AuthButton {...defaultProps} onClick={onClick} />);
wrapper.find('button').simulate('click');
expect(onClick.mock.calls.length).toBe(1);
});
});
9 changes: 9 additions & 0 deletions src/__tests__/testUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'; // eslint-disable-line
import renderer from 'react-test-renderer';

export const expectComponent = (children) => {
const component = renderer.create(children);
return expect(component);
};

export const noop = () => {};

0 comments on commit acc4481

Please sign in to comment.