このドキュメントとこの問題https://github.com/react-dnd/react-dnd/issues/453に従って、いくつかのテストを作成してい
私が抱えている問題は、テストレンダリングに関するものです。
ドキュメントが機能し、DragDropContextでコンポーネントをラップし、 TestUtils.renderIntoDocument
レンダリングする例を得ることができます。
これにより、 DragDropContextContainer
オブジェクトが返されます。
ただし、Enyzme mount
メソッドを使用してオブジェクトをレンダリングしようとすると、 $$typeof: Symbol(react.element)
オブジェクトが返されます。これでは、マネージャーを取得できません。
私は酵素を使用したいと思います-それは私が他の場所で私のテストに使用しているものだからです。
誰かがこれで助けを得ましたか?
私はこれを機能させました、これはそれがどのように見えるかです。 タイプスクリプトで。
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()
を呼び出す必要もありました。
それが役に立ったら、ここに私のテストファイルの1つがあります: https :
この問題は、最近のアクティビティがないため、自動的に古いものとしてマークされています。 それ以上のアクティビティが発生しない場合は閉じられます。 貢献していただきありがとうございます。
最も参考になるコメント
この同じ問題に遭遇しました。
wrapper.instance()
メソッドを使用して修正できますが、修正できるはずです。 https://github.com/react-dnd/react-dnd/issues/488でも説明されてい例えば
さらに、子コンポーネントのインスタンスを取得して
getHandlerId()
を呼び出す必要もありました。それが役に立ったら、ここに私のテストファイルの1つがあります: https :