์๋ง๋ ๋๊ตฐ๊ฐ๊ฐ getBoundingClientRect() ์ ํจ๊ป ์๋ํ๋ jsdom์ ์ค์ ํ๊ณ ๋๋ simulantjs๋ก ์์
ํ๊ณ ๋ด ์ฝ์์ ์ด๊ฒ์ ๋ค์ ๊ธฐ๋กํฉ๋๋ค->
const wrapper = mount(
<Provider store={store}>
<FullDecoratedBlock
uid={'test'}
setFocusedElement={setFocusedElement}/>
</Provider>, {attachTo: document.getElementById('app')})
expect(wrapper.find('.add-wrap').length).to.eql(0)
simulant.fire(document.body.querySelector('.wrapper-resize-button'), 'mousedown')
simulant.fire(document.body, 'mousemove', {target: {clientX: 51, clientY: 101}})
๋๊ตฐ๊ฐ ์์ด๋์ด๋ฅผ ๊ฐ์ง๊ณ ์์๊น์??
๋๋ ์ด ๋ฌธ์ ๋ฅผ ์ ์ดํดํ์ง ๋ชปํ๋ค. #1581, https://github.com/tmpvar/jsdom/issues/653 , https://github.com/tmpvar/jsdom/issues/1322์ ์์์์ธ ๊ฒ ๊ฐ์ต๋๋ค.
@domenic ๋ด๊ฐ ๊ตฌ์ฑ ์์๋ฅผ ๊ฐ์ง๊ณ ์์ต๋๋ค. ๋ง์ฐ์ค๋ฅผ ๊ตฌ์ฑ ์์์ ๋งจ ์๋๋ก ์ด๋ํ ๋ ๋ด ๊ตฌ์ฑ ์์๊ฐ buttop์ ํ์ํ๊ธฐ๋ฅผ ๊ธฐ๋ค๋ฆฌ๊ณ const rect = node.getBoundingClientRect()
์ด rect๊ฐ ๋ง์ฐ์ค์ ์ขํ๋ฅผ ์ป๊ณ ๊ตฌ์ฑ ์์์์ const showPlusButton = event.insideX && Math.abs(event.pos.y - event.componentRect.bottom) <= MOUSE_DISTANCE
๋ฅผ ์์ฑํฉ๋๋ค.
jsdom์ ๋ ๋๋ง์ ์ํํ์ง ์์ผ๋ฏ๋ก getBoundingClientRect()
๋ ํญ์ 0,0,0,0์ ๋ฐํํฉ๋๋ค. ๊ทธ๊ฒ์ ๋ณํ์ง ์์ ๊ฒ์
๋๋ค(์์ธก ๊ฐ๋ฅํ ์ฅ๊ธฐ์ ์ผ๋ก๋). ํจ์๋ฅผ ์กฐ๋กฑํ์ฌ ์์ํ ๊ฒฐ๊ณผ๋ฅผ ์๋ฎฌ๋ ์ดํธํ ์ ์์ต๋๋ค. ๋ํ #653์ ์ฐธ์กฐํ์ญ์์ค.
๋น์ ์ ๊ฐ์ ํ ์ ์์ต๋๋ค
const p = document.createElement('p')
p.getBoundingClientRect = jest.fn(() => ({
x: 851.671875,
y: 200.046875,
width: 8.34375,
height: 17,
top: 967.046875,
right: 860.015625,
bottom: 984.046875,
left: 851.671875,
}))
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋น์ ์ ๊ฐ์ ํ ์ ์์ต๋๋ค .getBoundingClientRect() API๊ฐ ์๋ํ๊ณ ๋ค์์ ์ํํฉ๋๋ค.