Skip to content

Commit

Permalink
Added testing
Browse files Browse the repository at this point in the history
  • Loading branch information
binoy14 authored and Brandon Dail committed Mar 23, 2017
1 parent bc334b2 commit 539e107
Show file tree
Hide file tree
Showing 3 changed files with 1,551 additions and 103 deletions.
40 changes: 40 additions & 0 deletions __tests__/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';
import {shallow, mount} from 'enzyme';
import Perimeter from '../src';

let component;
let mountedComponent;
let shallowComponent;
let onBreachFunction = jest.fn();

describe('Perimeter', () => {
beforeEach(() => {
window.addEventListener = jest.fn();
window.removeEventListener = jest.fn();

component = (
<Perimeter
onBreach={onBreachFunction}
padding={300}
>
<div className="perimeter-component">Perimeter</div>
</Perimeter>
);

shallowComponent = shallow(component)
mountedComponent = mount(component);
});
it('should return react component', () => {
expect(shallowComponent.length).toBe(1);
});
it('should render children', () => {
expect(shallowComponent.find(".perimeter-component").props().children).toBe("Perimeter");
});
it('should addEventListener on mount', () => {
expect(addEventListener).toHaveBeenCalledTimes(2);
});
it('should removeEventListener on unmount', () => {
mountedComponent.unmount();
expect(removeEventListener).toHaveBeenCalledTimes(2);
});
});
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"license": "MIT",
"scripts": {
"build": "rimraf lib && babel src --out-dir lib",
"prepublish": "npm run build"
"prepublish": "npm run build",
"test": "jest"
},
"repository": {
"type": "git",
Expand All @@ -21,7 +22,12 @@
"babel-plugin-transform-class-properties": "^6.23.0",
"babel-preset-env": "^1.2.2",
"babel-preset-react": "^6.23.0",
"enzyme": "^2.7.1",
"flow-bin": "^0.41.0",
"jest": "^19.0.2",
"react": "^15.4.2",
"react-addons-test-utils": "^15.4.2",
"react-dom": "^15.4.2",
"rimraf": "^2.6.1"
},
"peerDependencies": {
Expand Down
Loading

0 comments on commit 539e107

Please sign in to comment.