S
S
stepan1322019-11-29 21:00:44
Unit testing
stepan132, 2019-11-29 21:00:44

Is testing done correctly?

Hello. I'm covering an application with tests and I need to test a component that is wrapped in a redux connect hook. Is the following code implemented correctly:

import React from 'react';
import { Provider } from 'react-redux';
import { shallow } from 'enzyme';

import FilmPage from '../../pages/FilmPage';
import store from '../../store/Store';

describe('film page', () => {
    it('correct film title display', () => {
        let filmPage = shallow(
            <Provider store={store}>
                <FilmPage />
            </Provider>
        );
        expect(filmPage.find('div')).toHaveLength(0);
    })
})

I am interested in whether it is correct to wrap the tested component in a provider with a real store that is used in the application, or is there a more correct way? Thanks in advance for any help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2019-11-29
@dimoff66

As an option

import { createHashHistory } from 'history'
import { createStore } from 'redux'
import reducer from 'reducer'

import { Provider } from 'react-redux'
import { store } from 'store'

const history = createHashHistory()
const store = createStore(reducer(history))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question