1
+ import React from 'react' ;
2
+ import { configure , shallow } from 'enzyme' ;
3
+ import Adapter from 'enzyme-adapter-react-16' ;
4
+ import Dropdown from '../components/Dropdown' ;
5
+
6
+ configure ( { adapter : new Adapter ( ) } ) ;
7
+
8
+ describe ( 'unit testing for Dropdown.jsx' , ( ) => {
9
+ let wrapper ;
10
+ const props = {
11
+ options : [
12
+ { value : 2000 , label : '0.5x' } ,
13
+ { value : 1000 , label : '1.0x' } ,
14
+ { value : 500 , label : '2.0x' } ,
15
+ ] ,
16
+ handleChangeSpeed : jest . fn ( ) ,
17
+ selectedOption : { value : 1000 , label : '1.0x' }
18
+ } ;
19
+ beforeEach ( ( ) => {
20
+ wrapper = shallow ( < Dropdown { ...props } /> ) ;
21
+ } ) ;
22
+
23
+ describe ( 'Component' , ( ) => {
24
+ test ( 'array of objects that have value and label should be options props' , ( ) => {
25
+ expect ( wrapper . props ( ) . options ) . toEqual ( props . options ) ;
26
+ } ) ;
27
+ test ( 'selectedOption should be value property' , ( ) => {
28
+ expect ( wrapper . props ( ) . value ) . toEqual ( props . selectedOption ) ;
29
+ } )
30
+ } )
31
+
32
+ describe ( 'handlechangeSpeed' , ( ) => {
33
+ test ( 'should invoke handleChangeSpeed onChange' , ( ) => {
34
+ wrapper . simulate ( 'change' , { value : 2000 , label : '0.5x' } ) ;
35
+ expect ( props . handleChangeSpeed ) . toHaveBeenCalled ( ) ;
36
+ } ) ;
37
+ } ) ;
38
+ } ) ;
0 commit comments