Skip to content

Commit 539e107

Browse files
binoy14Brandon Dail
authored andcommitted
Added testing
1 parent bc334b2 commit 539e107

File tree

3 files changed

+1551
-103
lines changed

3 files changed

+1551
-103
lines changed

__tests__/index.spec.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
import {shallow, mount} from 'enzyme';
3+
import Perimeter from '../src';
4+
5+
let component;
6+
let mountedComponent;
7+
let shallowComponent;
8+
let onBreachFunction = jest.fn();
9+
10+
describe('Perimeter', () => {
11+
beforeEach(() => {
12+
window.addEventListener = jest.fn();
13+
window.removeEventListener = jest.fn();
14+
15+
component = (
16+
<Perimeter
17+
onBreach={onBreachFunction}
18+
padding={300}
19+
>
20+
<div className="perimeter-component">Perimeter</div>
21+
</Perimeter>
22+
);
23+
24+
shallowComponent = shallow(component)
25+
mountedComponent = mount(component);
26+
});
27+
it('should return react component', () => {
28+
expect(shallowComponent.length).toBe(1);
29+
});
30+
it('should render children', () => {
31+
expect(shallowComponent.find(".perimeter-component").props().children).toBe("Perimeter");
32+
});
33+
it('should addEventListener on mount', () => {
34+
expect(addEventListener).toHaveBeenCalledTimes(2);
35+
});
36+
it('should removeEventListener on unmount', () => {
37+
mountedComponent.unmount();
38+
expect(removeEventListener).toHaveBeenCalledTimes(2);
39+
});
40+
});

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"license": "MIT",
66
"scripts": {
77
"build": "rimraf lib && babel src --out-dir lib",
8-
"prepublish": "npm run build"
8+
"prepublish": "npm run build",
9+
"test": "jest"
910
},
1011
"repository": {
1112
"type": "git",
@@ -21,7 +22,12 @@
2122
"babel-plugin-transform-class-properties": "^6.23.0",
2223
"babel-preset-env": "^1.2.2",
2324
"babel-preset-react": "^6.23.0",
25+
"enzyme": "^2.7.1",
2426
"flow-bin": "^0.41.0",
27+
"jest": "^19.0.2",
28+
"react": "^15.4.2",
29+
"react-addons-test-utils": "^15.4.2",
30+
"react-dom": "^15.4.2",
2531
"rimraf": "^2.6.1"
2632
},
2733
"peerDependencies": {

0 commit comments

Comments
 (0)