Skip to content

Commit

Permalink
Setup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Jan 2, 2018
1 parent ac55a11 commit fb1d6af
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"cleancss": "cleancss -o dist/react-modal.min.css dist/react-modal.css",
"demo": "http-server -p 8000 docs/",
"lint": "eslint ./src",
"lint:fix": "eslint --fix ./src",
"test": "tap test/*.js --node-arg=--require --node-arg=babel-register --node-arg=--require --node-arg=babel-polyfill",
"coveralls": "tap test/*.js --coverage --coverage-report=text-lcov --nyc-arg=--require --nyc-arg=babel-register --nyc-arg=--require --nyc-arg=babel-polyfill | coveralls",
"dev": "cd examples; webpack-dev-server --hot --inline --host 0.0.0.0 --port 8000 --content-base ../docs"
Expand Down Expand Up @@ -66,6 +65,8 @@
"clean-css-cli": "~4.1.10",
"coveralls": "~3.0.0",
"css-loader": "~0.28.7",
"enzyme": "~3.2.0",
"enzyme-adapter-react-16": "~1.1.1",
"eslint": "~4.14.0",
"eslint-config-trendmicro": "~1.3.0",
"eslint-loader": "~1.9.0",
Expand All @@ -77,6 +78,7 @@
"find-imports": "~0.5.2",
"html-webpack-plugin": "~2.30.1",
"http-server": "~0.10.0",
"jsdom": "~11.5.1",
"nib": "~1.1.2",
"react": "^0.14.0 || >=15.0.0",
"react-dom": "^0.14.0 || >=15.0.0",
Expand Down
33 changes: 33 additions & 0 deletions setupTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import { JSDOM } from 'jsdom';

// React 16 Enzyme adapter
Enzyme.configure({ adapter: new Adapter() });

// Ignore `.styl` files
require.extensions['.styl'] = () => {
return;
};

// JSDOM
const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
const { window } = jsdom;

const copyProps = (src, target) => {
const props = Object.getOwnPropertyNames(src)
.filter(prop => typeof target[prop] === 'undefined')
.reduce((result, prop) => ({
...result,
[prop]: Object.getOwnPropertyDescriptor(src, prop),
}), {});
Object.defineProperties(target, props);
};

global.window = window;
global.document = window.document;
global.navigator = {
userAgent: 'node.js',
};

copyProps(window, global);
19 changes: 18 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
import React from 'react';
import { mount } from 'enzyme';
import { test } from 'tap';
import '../setupTests';
import Modal from '../src';

test('noop', (t) => {
test('<Modal />', (t) => {
const wrapper = mount((
<Modal>
<Modal.Header>
<Modal.Title>
</Modal.Title>
</Modal.Header>
<Modal.Body>
</Modal.Body>
<Modal.Footer>
</Modal.Footer>
</Modal>
));
t.equal(wrapper.find(Modal).length, 1, 'should render <Modal /> component');
t.end();
});

0 comments on commit fb1d6af

Please sign in to comment.