components-state-testing.mo

Prerequisites (~5 min)

Steps (~30 min)

  • Create a simple test:

    describe('ComponentToTest', () => {
    it('should test a simple true === true', () => {
      expect(true).toBe(true);
    });
    });
  • Import the necessary packages and your component:

    ```javascript

    import React from 'react';

    import renderer from 'react-test-renderer';

import ComponentToTest from './ComponentToTest.component';

  • Use this instance in your it test, the property getInstance() allows you to access all the properties of the component class. Now you can test your initial state:

    • Add new tests, faking a user action and the impact it has on the component state:

Last updated