You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add the first test of your component, and remove the true === true
Render your component with react-test-renderer, it will transform your component in a JavaScript object instance, which you will be able to test, accessing its state, triggering its methods:
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:
describe('ComponentToTest',()=>{// ...it('should init the state',()=>{expect(component.getInstance().state).toEqual({fakeStatus: 'init',});});});
Add new tests, faking a user action and the impact it has on the component state:
describe('ComponentToTest',()=>{// ...it('should set the component fakeStatus to "inProgress"',()=>{component.getInstance().onButtonPress();expect(component.getInstance().state).toEqual({fakeStatus: 'inProgress',});});// ...});