Cannot test with enzyme and jest

オープン
#264 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
javascript, react
領域
frontend, testing

調査の方向性

Issue に示されているパスにある ErrorDialog コンポーネントとそのテストから始め、インポートされた rc-dialog コンポーネントが Enzyme shallow によってどのようにレンダリングされるかを調べます。報告されたテキスト出力を再現し、テストまたはコンポーネントの動作のどちらが誤っているのかを判断します。テストで期待されるメッセージとコードの不在を確実に確認できるか、必要なプロジェクト変更によって issue が明確になれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Hi, I was trying to test the dialog component but it's not working.
Here is my component code

import Toast from '@/utils/Toast';
import PropTypes from 'prop-types';
import Dialog from 'rc-dialog';
import React from 'react';
import enhanceMessage from './enhanceMessage';

function ErrorDialog({ dismissError, error, breakoutFullText }) {
  const { message, code, name } = error || {};
  const enhancedMessage = enhanceMessage(message, code, breakoutFullText, name);
  const styles = {
    dialogContent: {
      display: ' flex',
      flexDirection: 'column',
      justifyContent: 'center',
      alignItems: 'center',
    },
  };
  if (code === 53105) {
    Toast.info(breakoutFullText);
    return true;
  }
  return error !== null ? (
    <Dialog
      title="Error"
      className="main-dialog"
      style={{ height: 200, width: 400, top: '20%' }}
      onClose={() => dismissError()}
      visible={error !== null}
      destroyOnClose
      animation="zoom"
      maskAnimation="fade"
      footer={
        <button type="button" className="btn button" key="close" onClick={dismissError}>
          OK
        </button>
      }>
      <div style={styles.dialogContent}>
        <h3>{name === 'NotFoundError' ? 'No camera found' : enhancedMessage}</h3>
        <div>
          {code && code !== 53105 && (
            <pre>
              <code>
                Error Code:
                {code}
              </code>
            </pre>
          )}
        </div>
      </div>
    </Dialog>
  ) : null;
}

Here is my test code

import ErrorDialog from '@/components/TwilioVideoMeeting/ErrorDialog/ErrorDialog';
import { shallow } from 'enzyme';
import Dialog from 'rc-dialog';
import React from 'react';

describe('Testing the ErrorDialog component', () => {
  const message = 'Fake Error message';
 
  it('should display error message but not error code is the later does not exist', () => {
    const error = { message };
    const wrapper = shallow(<ErrorDialog dismissError={() => {}} error={error} />);
    expect(wrapper.find(Dialog).text()).toContain(message);
    expect(wrapper.find('code').exists()).toBe(false);
  });
});

It throws following error
the ErrorDialog component › should display error message but not error code is the later does not exist

expect(received).toContain(expected) // indexOf

Expected substring: "Fake Error message"
Received string:    "< />"

Any Help would be appreciated

主要言語
TypeScript
スター
454
フォーク
208
平均マージ
1時間 9分
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

react-component/dialog のほかの issue

react-component/dialog の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。