vendredi 24 août 2018

How to get props in jest

I am using shallow from enzyme. I want to get props that I have passed to component in my testing file. Like so in example but I am getting undefined.

console.log(wrapper.props()) 

should return object of props but it returning some jsx object.

Kindly assist how to get props of some component for which I want to write test cases.

Here is my code:

import React from 'react';
import {
    configure,
    shallow
} from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

import MenuList from './MenuList';
import {
    Link
} from 'react-router-dom';

configure({
    adapter: new Adapter()
});

const footerItem = {
    label: '',
    links: [{
        label: '',
        link: '/'
    }]
}

describe('<MenuList />', () => {

            let wrapper;
            beforeEach(() => {
                    wrapper = shallow( < MenuList footerItem = {
                            footerItem
                        }
                        / > );
                    });

                it('should render Link', () => {
                    console.log(wrapper.props().footerItem); // This should print footerItem object but returning  defined
                    expect(wrapper.find(Link).length).toBeGreaterThan(0);
                });
            });

Aucun commentaire:

Enregistrer un commentaire