ka0824 / baseball

0 stars 0 forks source link

[Front] jest로 유닛테스트 하기 위해 돔 구조 재현하기 #4

Open ka0824 opened 2 years ago

ka0824 commented 2 years ago

문제 상황

import React from 'react';
import Renderer from 'react-test-renderer';
import Game from '../components/Game/Game';
import store from '../store/store';
import { Provider } from 'react-redux';

describe('Game component', () => {
    let component = null;

    it('renders', () => {
        component = Renderer.create(   // 
        <Provider store={store}>
            <Game />
        </Provider>
        )
    });

   console.log(component)                 // null 값이 나옴. 
                                          // 안에 있는 state와 이벤트 리스너를 테스트하기 위해서는 어떻게 해야할까?
})


해결책 고려하기

  • jest, react, unit test를 검색어로 조합하여 구글링
  • github에 오픈되어 있는 프로젝트 참고해보기


시도해봤던 방법

  • getInstance()를 붙여보기
  • 이유: 블로그에 작성된 코드를 참고
    console.log(component.getInstance())         // 그대로 null이 나옴


console.log(component); // 생각했던 형태가 아님.

ka0824 commented 2 years ago

시도

다음 시도