Skip to content

Commit

Permalink
Setup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Dec 22, 2017
1 parent 5d10ee2 commit cf2a386
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 10 deletions.
20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"clean": "rm -f {lib,dist}/*",
"cleancss": "cleancss -o dist/react-sidenav.min.css dist/react-sidenav.css",
"demo": "http-server -p 8000 docs/",
"lint": "eslint ./src",
"lint:fix": "eslint --fix ./src",
"lint": "eslint ./src ./test",
"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 @@ -69,27 +68,30 @@
"coveralls": "~3.0.0",
"css-loader": "~0.28.7",
"ensure-array": "~1.0.0",
"enzyme": "~3.2.0",
"enzyme-adapter-react-16": "~1.1.1",
"eslint": "~4.13.1",
"eslint-config-trendmicro": "~1.1.0",
"eslint-config-trendmicro": "~1.2.0",
"eslint-loader": "~1.9.0",
"eslint-plugin-import": "~2.8.0",
"eslint-plugin-jsx-a11y": "~6.0.2",
"eslint-plugin-jsx-a11y": "~6.0.3",
"eslint-plugin-react": "~7.5.1",
"extract-text-webpack-plugin": "~3.0.2",
"file-loader": "~1.1.5",
"file-loader": "~1.1.6",
"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": "~16.2.0",
"react-dom": "~16.2.0",
"style-loader": "~0.19.0",
"styled-components": "~2.2.4",
"style-loader": "~0.19.1",
"styled-components": "~2.3.3",
"stylint": "~1.5.9",
"stylint-loader": "~1.0.0",
"stylus-loader": "~3.0.1",
"tap": "~11.0.0",
"trendmicro-ui": "~0.4.4",
"tap": "~11.0.1",
"trendmicro-ui": "~0.5.0",
"url-loader": "~0.6.2",
"webpack": "~3.10.0",
"webpack-dev-server": "~2.9.7"
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);
22 changes: 21 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
import React from 'react';
import { mount } from 'enzyme';
import { test } from 'tap';
import '../setupTests';
import SideNav, { Toggle, Nav, NavItem, NavIcon, NavText } from '../src';

test('noop', (t) => {
test('<SideNav />', (t) => {
const wrapper = mount((
<SideNav>
<Toggle />
<Nav>
<NavItem>
<NavIcon />
<NavText />
</NavItem>
<NavItem>
<NavIcon />
<NavText />
</NavItem>
</Nav>
</SideNav>
));
t.equal(wrapper.find(SideNav).length, 1, 'should render <SideNav /> component');
t.end();
});

0 comments on commit cf2a386

Please sign in to comment.