@@ -16,7 +16,8 @@ const getProps = (props) => {
1616}
1717
1818const popperInstanceStub = ( ) => ( {
19- onUpdate : sinon . spy ( ) ,
19+ onCreate : sinon . stub ( ) ,
20+ onUpdate : sinon . stub ( ) ,
2021 scheduleUpdate : sinon . spy ( ) ,
2122 destroy : sinon . spy ( ) ,
2223} )
@@ -91,58 +92,65 @@ describe('<PortalPopper />', () => {
9192 describe ( 'Popper#onUpate' , ( ) => {
9293 it ( 'updates the arrow props if specified' , ( ) => {
9394 const popperInstance = popperInstanceStub ( )
94- const component = mount ( < PortalPopper { ...getProps ( { Popper : popperStub ( popperInstance ) } ) } /> )
95- popperInstance . onUpdate ( { offsets : { arrow : { left : 5 , top : 10 } } } )
95+ const Popper = popperStub ( popperInstance )
96+ const component = mount ( < PortalPopper { ...getProps ( { Popper } ) } /> )
97+ Popper . firstCall . args [ 2 ] . onUpdate ( { offsets : { arrow : { left : 5 , top : 10 } } } )
9698 expect ( component . ref ( 'arrow' ) . prop ( 'style' ) . left ) . to . equal ( 5 )
9799 expect ( component . ref ( 'arrow' ) . prop ( 'style' ) . top ) . to . equal ( 10 )
98100 } )
99101
100102 it ( 'does not update the arrow props if not specified' , ( ) => {
101103 const popperInstance = popperInstanceStub ( )
102- const component = mount ( < PortalPopper { ...getProps ( { Popper : popperStub ( popperInstance ) } ) } /> )
103- popperInstance . onUpdate ( { offsets : { } } )
104+ const Popper = popperStub ( popperInstance )
105+ const component = mount ( < PortalPopper { ...getProps ( { Popper } ) } /> )
106+ Popper . firstCall . args [ 2 ] . onUpdate ( { offsets : { } } )
104107 expect ( component . ref ( 'arrow' ) . prop ( 'style' ) . left ) . to . equal ( 0 )
105108 expect ( component . ref ( 'arrow' ) . prop ( 'style' ) . top ) . to . equal ( 0 )
106109 } )
107110
108111 it ( 'only updates the arrow props that are specified' , ( ) => {
109112 const popperInstance = popperInstanceStub ( )
110- const component = mount ( < PortalPopper { ...getProps ( { Popper : popperStub ( popperInstance ) } ) } /> )
111- popperInstance . onUpdate ( { offsets : { arrow : { top : 20 } } } )
113+ const Popper = popperStub ( popperInstance )
114+ const component = mount ( < PortalPopper { ...getProps ( { Popper } ) } /> )
115+ Popper . firstCall . args [ 2 ] . onUpdate ( { offsets : { arrow : { top : 20 } } } )
112116 expect ( component . ref ( 'arrow' ) . prop ( 'style' ) . left ) . to . equal ( null )
113117 expect ( component . ref ( 'arrow' ) . prop ( 'style' ) . top ) . to . equal ( 20 )
114118 } )
115119
116120 it ( 'rounds the arrow props' , ( ) => {
117121 const popperInstance = popperInstanceStub ( )
118- const component = mount ( < PortalPopper { ...getProps ( { Popper : popperStub ( popperInstance ) } ) } /> )
119- popperInstance . onUpdate ( { offsets : { arrow : { left : 7.2 , top : 20.8 } } } )
122+ const Popper = popperStub ( popperInstance )
123+ const component = mount ( < PortalPopper { ...getProps ( { Popper } ) } /> )
124+ Popper . firstCall . args [ 2 ] . onUpdate ( { offsets : { arrow : { left : 7.2 , top : 20.8 } } } )
120125 expect ( component . ref ( 'arrow' ) . prop ( 'style' ) . left ) . to . equal ( 7 )
121126 expect ( component . ref ( 'arrow' ) . prop ( 'style' ) . top ) . to . equal ( 21 )
122127 } )
123128
124129 it ( 'updates the popper props if specified' , ( ) => {
125130 const popperInstance = popperInstanceStub ( )
126- const component = mount ( < PortalPopper { ...getProps ( { Popper : popperStub ( popperInstance ) } ) } /> )
127- popperInstance . onUpdate ( { offsets : { popper : { position : 'relative' , left : 2 , top : 4 } } } )
131+ const Popper = popperStub ( popperInstance )
132+ const component = mount ( < PortalPopper { ...getProps ( { Popper } ) } /> )
133+ Popper . firstCall . args [ 2 ] . onUpdate ( { offsets : { popper : { position : 'relative' , left : 2 , top : 4 } } } )
128134 expect ( component . find ( Portal ) . prop ( 'style' ) . position ) . to . equal ( 'relative' )
129135 expect ( component . find ( Portal ) . prop ( 'style' ) . transform ) . to . equal ( 'translate3d(2px, 4px, 0)' )
130136 expect ( component . find ( Portal ) . prop ( 'style' ) . WebkitTransform ) . to . equal ( 'translate3d(2px, 4px, 0)' )
131137 } )
132138
133139 it ( 'does not update the popper props if not specified' , ( ) => {
134140 const popperInstance = popperInstanceStub ( )
135- const component = mount ( < PortalPopper { ...getProps ( { Popper : popperStub ( popperInstance ) } ) } /> )
136- popperInstance . onUpdate ( { offsets : { } } )
141+ const Popper = popperStub ( popperInstance )
142+ const component = mount ( < PortalPopper { ...getProps ( { Popper } ) } /> )
143+ Popper . firstCall . args [ 2 ] . onUpdate ( { offsets : { } } )
137144 expect ( component . find ( Portal ) . prop ( 'style' ) . position ) . to . equal ( 'absolute' )
138145 expect ( component . find ( Portal ) . prop ( 'style' ) . transform ) . to . equal ( 'translate3d(0px, 0px, 0)' )
139146 expect ( component . find ( Portal ) . prop ( 'style' ) . WebkitTransform ) . to . equal ( 'translate3d(0px, 0px, 0)' )
140147 } )
141148
142149 it ( 'rounds the popper props' , ( ) => {
143150 const popperInstance = popperInstanceStub ( )
144- const component = mount ( < PortalPopper { ...getProps ( { Popper : popperStub ( popperInstance ) } ) } /> )
145- popperInstance . onUpdate ( { offsets : { popper : { left : 15.2 , top : 2.8 } } } )
151+ const Popper = popperStub ( popperInstance )
152+ const component = mount ( < PortalPopper { ...getProps ( { Popper } ) } /> )
153+ Popper . firstCall . args [ 2 ] . onUpdate ( { offsets : { popper : { left : 15.2 , top : 2.8 } } } )
146154 expect ( component . find ( Portal ) . prop ( 'style' ) . transform ) . to . equal ( 'translate3d(15px, 3px, 0)' )
147155 expect ( component . find ( Portal ) . prop ( 'style' ) . WebkitTransform ) . to . equal ( 'translate3d(15px, 3px, 0)' )
148156 } )
0 commit comments