mardi 20 août 2019

How to test a React Component that has JQuery object in constructor?

I'd like to write a spec for a React component called DiscountDetails that uses jquery in its constructor. How can I get a test set up using enzyme?

This is what DiscountDetails Component looks like:

class DiscountDetails extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      discount_details: [],
      discount_type: $("#auto_discount_discount_type").val(),
      activities: $("#auto_discount_activities").val(),
      booking_type: $("#auto_discount_booking_type").val(),
    };
  }


In my spec file, I've tried

describe("<DiscountDetails />", () => {
  it("is testable", () => {
    const subject = () => <DiscountDetails />;
    expect(subject).to.have.lengthOf(1);
  });
});


but subject is undefined.

Aucun commentaire:

Enregistrer un commentaire