Jsdom: getBoundingClientRect()์— ๋Œ€ํ•œ js dom ์„ค์ •

์— ๋งŒ๋“  2016๋…„ 08์›” 25์ผ  ยท  4์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: jsdom/jsdom

screen shot 2016-08-25 at 4 57 33 pm

์•„๋งˆ๋„ ๋ˆ„๊ตฐ๊ฐ€๊ฐ€ getBoundingClientRect() ์™€ ํ•จ๊ป˜ ์ž‘๋™ํ•˜๋Š” jsdom์„ ์„ค์ •ํ•˜๊ณ  ๋‚˜๋Š” simulantjs๋กœ ์ž‘์—…ํ•˜๊ณ  ๋‚ด ์ฝ˜์†”์€ ์ด๊ฒƒ์„ ๋‹ค์‹œ ๊ธฐ๋กํ•ฉ๋‹ˆ๋‹ค->
screen shot 2016-08-25 at 5 03 42 pm

    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}})

๋ˆ„๊ตฐ๊ฐ€ ์•„์ด๋””์–ด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์„๊นŒ์š”??

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

๋‹น์‹ ์€ ๊ฐ€์ • ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค .getBoundingClientRect() API๊ฐ€ ์ž‘๋™ํ•˜๊ณ  ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

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,
    }))

๋ชจ๋“  4 ๋Œ“๊ธ€

๋‚˜๋Š” ์ด ๋ฌธ์ œ๋ฅผ ์ž˜ ์ดํ•ดํ•˜์ง€ ๋ชปํ•œ๋‹ค. #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์„ ์ฐธ์กฐํ•˜์‹ญ์‹œ์˜ค.

๋‹น์‹ ์€ ๊ฐ€์ • ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค .getBoundingClientRect() API๊ฐ€ ์ž‘๋™ํ•˜๊ณ  ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

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,
    }))
์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰