์ด ๋ฌธ์ ์ ์ด ๋ฌธ์ https://github.com/react-dnd/react-dnd/issues/453์ ๋ฐ๋ผ ๋ช ๊ฐ์ง ํ ์คํธ๋ฅผ ์์ฑํ๊ณ ์์ต๋๋ค.
๋ด๊ฐ ๊ฐ์ง ๋ฌธ์ ๋ ํ ์คํธ ๋ ๋๋ง์ ๊ดํ ๊ฒ์ ๋๋ค.
๋ฌธ์์์ ์ ๊ณตํ๋ ์์ ๋ฅผ ์ป์ ์ ์์ต๋๋ค. DragDropContext์์ ๊ตฌ์ฑ ์์๋ฅผ ๋ํํ๊ณ TestUtils.renderIntoDocument
๋ ๋๋งํฉ๋๋ค.
DragDropContextContainer
๊ฐ์ฒด๋ฅผ ๋ฐํํฉ๋๋ค.
๊ทธ๋ฌ๋ Enyzme mount
๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ ๊ฐ์ฒด๋ฅผ ๋ ๋๋งํ๋ ค๊ณ ํ๋ฉด $$typeof: Symbol(react.element)
๊ฐ์ฒด๋ฅผ ๋ฐํํ๋ฏ๋ก ๊ด๋ฆฌ์๋ฅผ ์ป์ ์ ์์ต๋๋ค.
Enzyme์ ์ฌ์ฉํ๋ ๊ฒ์ ์ ํธํฉ๋๋ค. ๋ค๋ฅธ ๊ณณ์์ ํ ์คํธ์ ์ฌ์ฉํ๊ณ ์๊ธฐ ๋๋ฌธ์ ๋๋ค.
๋๊ตฌ๋ ์ง ์ด๊ฒ๊ณผ ๊ด๋ จํ์ฌ ๋์์ ๋ฐ์์ต๋๊น?
๋ฐฉ๊ธ ์ด ์์ ์ ์ํํ์ต๋๋ค. ๋ค์๊ณผ ๊ฐ์ต๋๋ค. ํ์ดํ์คํฌ๋ฆฝํธ์์.
import { ThingIAmTesting } from '../file/where/it/lives';
describe('It is a test!', () => {
let props;
let component;
const getComponent = () => {
let OriginalComponent = (ThingIAmTesting as any).DecoratedComponent;
let identity = el => el;
if (!component) {
component = Enzyme.shallow(
<OriginalComponent {...props} connectDragSource={identity} />
);
return component
}
beforeEach (() => {
props = {
prop: 'stuff',
}
component = undefined;
})
it('should render', () => {
let component = getComponent();
expect(component).toMatchSnapshot();
});
})
์ด ๊ฐ์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค. wrapper.instance()
๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ ์์ ํ ์ ์๊ณ ์ฌ๋ฌ๋ถ์ด ํ ์ ์์ ๊ฒ์ผ๋ก ๊ธฐ๋ํฉ๋๋ค. https://github.com/react-dnd/react-dnd/issues/488 ์๋ ์ค๋ช
๋์ด ์์ต๋๋ค
์
const Context = wrapInTestContext(Component)
const wrapper = mount(<Context />)
const manager = wrapper.instance().getManager()
const backend = manager.getBackend()
๋ํ getHandlerId()
๋ฅผ ํธ์ถํ๋ ํ์ ๊ตฌ์ฑ ์์์ ์ธ์คํด์ค๋ ๊ฐ์ ธ์์ผ ํ์ต๋๋ค.
๋์์ด ๋๋ค๋ฉด ์ฌ๊ธฐ ๋ด ํ ์คํธ ํ์ผ ์ค ํ๋๊ฐ ์์ต๋๋ค. https://gist.github.com/gilleswittenberg/142fe49e1115b5a1936562b2284e1ab7
์ด ๋ฌธ์ ๋ ์ต๊ทผ ํ๋์ด ์์๊ธฐ ๋๋ฌธ์ ์๋์ผ๋ก ์ค๋๋ ๊ฒ์ผ๋ก ํ์๋์์ต๋๋ค. ๋ ์ด์ ํ๋์ด ์์ผ๋ฉด ํ์๋ฉ๋๋ค. ๊ทํ์ ๊ธฐ์ฌ์ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ด ๊ฐ์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค.
wrapper.instance()
๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ ์์ ํ ์ ์๊ณ ์ฌ๋ฌ๋ถ์ด ํ ์ ์์ ๊ฒ์ผ๋ก ๊ธฐ๋ํฉ๋๋ค. https://github.com/react-dnd/react-dnd/issues/488 ์๋ ์ค๋ช ๋์ด ์์ต๋๋ค์
๋ํ
getHandlerId()
๋ฅผ ํธ์ถํ๋ ํ์ ๊ตฌ์ฑ ์์์ ์ธ์คํด์ค๋ ๊ฐ์ ธ์์ผ ํ์ต๋๋ค.๋์์ด ๋๋ค๋ฉด ์ฌ๊ธฐ ๋ด ํ ์คํธ ํ์ผ ์ค ํ๋๊ฐ ์์ต๋๋ค. https://gist.github.com/gilleswittenberg/142fe49e1115b5a1936562b2284e1ab7