ReactJs Getting text value from React Element child in enzyme reactjs getting started,reactjs getting,reactjs getting data from server,

I have the following component as part of my large component.

<UI.Field
   horizontal
     value={
       <FormattedNumber
         style="currency"
         currency="EUR"
         data-service-fee
         value={booking.service_fee_cents || 8000 / 100}
       />
       }
      label={`${base}service_fee`}
      />

I'm writing tests for the component.

it('renders default value if service fee is null', () => {
      wrapper.setProps({
        booking: {
          ...make(booking),
          service_fee_cents: null,
        },
      })
      expect(wrapper.find('[data-service-fee]').text()).toBe('€80.00')
    })

What I'm trying to do is to get the value inside the field named data-service-fee. But wrapper.find('[data-service-fee]') always return null.

When I tried wrapper.find('[label*="service_fee"]').text() it return the component itself instead of text ?

What am I doing wrong ?

Answer:1



  1. reactjs getting started
  2. reactjs getting
  3. reactjs getting data from server
  4. react getting state

I have a React component with the following proptypes defined: NavBar.propTypes = { navbar: PropTypes.arrayOf(PropTypes.shape({ brand: PropTypes.shape({ linkTo: PropTypes.string, ...

I have a React component with the following proptypes defined: NavBar.propTypes = { navbar: PropTypes.arrayOf(PropTypes.shape({ brand: PropTypes.shape({ linkTo: PropTypes.string, ...

I trying to setup a very simple App to get familar with using SOCKET.IO in an React APP. Server looks like this: const io = require('socket.io')(); io.origins('*:*'); io.on('connection', (client) =&...

I trying to setup a very simple App to get familar with using SOCKET.IO in an React APP. Server looks like this: const io = require('socket.io')(); io.origins('*:*'); io.on('connection', (client) =&...