pass props in another component in enzyme code example

Example 1: pass props in another component in enzyme

import React from 'react'
import { shallow } from 'enzyme'
import App from './App'
import Modal from './Modal'

test('renders learn react link', () => {
  const property = {
    comps: 'john doe'
  }
  const wrapper = shallow(<App {...property} />)
  const getContent = wrapper.find(Modal).prop('comps')
  expect(getContent).toBe('john doex')
})

Example 2: how to pass property component in react enzyme

import React from 'react'
import { shallow } from 'enzyme'
import { configure } from 'enzyme'
import Adapter from 'enzyme-adapter-react-15'

import SongLink from '../components/SongLink'

configure({ adapter: new Adapter() })

test('it renders correctly', () => { 
  const component = shallow(<SongLink />)
  let tree = component.toJSON()
  expect(tree).toMatchSnapshot()
})

Example 3: how to pass property component in react enzyme

import React from 'react'
import { shallow } from 'enzyme'
import { configure } from 'enzyme'
import Adapter from 'enzyme-adapter-react-15'

import SongLink from '../components/SongLink'

configure({ adapter: new Adapter() })   

test('it renders correctly', () => {

  // This is where I tried to imitate the props and pass them in. 

  const songLinkProps = {
    result: {
      id: '6rPO02ozF3bM7NnOV4h6s2'
    },
    handleClick: () => {
      console.log('click')
    }
  }

  const component = shallow(<SongLink key={songLinkProps.result.id} />)
  let tree = component.toJSON()
  expect(tree).toMatchSnapshot()
})

Tags:

Misc Example