React-dnd: ReactTestUtilsではなくEnzymeを使用したテスト

作成日 2017年11月26日  ·  3コメント  ·  ソース: react-dnd/react-dnd

このドキュメントとこの問題https://github.com/react-dnd/react-dnd/issues/453に従って、いくつかのテストを作成してい

私が抱えている問題は、テストレンダリングに関するものです。

ドキュメントが機能し、DragDropContextでコンポーネントをラップし、 TestUtils.renderIntoDocumentレンダリングする例を得ることができます。

これにより、 DragDropContextContainerオブジェクトが返されます。

ただし、Enyzme mountメソッドを使用してオブジェクトをレンダリングしようとすると、 $$typeof: Symbol(react.element)オブジェクトが返されます。これでは、マネージャーを取得できません。

私は酵素を使用したいと思います-それは私が他の場所で私のテストに使用しているものだからです。

誰かがこれで助けを得ましたか?

wontfix

最も参考になるコメント

この同じ問題に遭遇しました。 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

全てのコメント3件

私はこれを機能させました、これはそれがどのように見えるかです。 タイプスクリプトで。

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

この問題は、最近のアクティビティがないため、自動的に古いものとしてマークされています。 それ以上のアクティビティが発生しない場合は閉じられます。 貢献していただきありがとうございます。

このページは役に立ちましたか?
0 / 5 - 0 評価