File tree Expand file tree Collapse file tree 3 files changed +1551
-103
lines changed
Expand file tree Collapse file tree 3 files changed +1551
-103
lines changed Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 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" ,
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" : {
You can’t perform that action at this time.
0 commit comments