Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@jest-decorated/react

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jest-decorated/react

Decorators for writing jest-based tests for react components.

Source
npmnpm
Version
0.0.10
Version published
Weekly downloads
33
-2.94%
Maintainers
1
Weekly downloads
 
Created
Source

Decorators for writing jest-based tests for react components

Extension of @jest-decorated package.

Utilities for testing react components. Compatible with enzyme, testing-libray and react-dom/test-utils.

Example usage

Make sure to register ReactTestRunner on your parent test:

@Describe()
@RunWith(ReactTestRunner)
class MyComponentTest {
    
    @ComponentContainer()
    container;
    
    @ComponentProvider()
    provider(passedProps) {
        return render(<MyComponent {...passedProps} />, this.container);
    }
    
    @It("changes value when clicked, calls onChange")
    @WithProps({ onChange: jest.fn() })
    shouldToggle(returnValueOfComponentProvider, passedPops) {
        const button = document.querySelector("[data-testid=toggle]");
        expect(button.innerHTML).toBe("Turn on");
    
        button.dispatchEvent(new MouseEvent("click", { bubbles: true }));
        expect(passedPops.onChange).toHaveBeenCalledTimes(1);
        expect(button.innerHTML).toBe("Turn off");
    }
}

Decorators

@Act

@ActAsync

@ComponentContainer

@ComponentProvider

@DefaultContext

@DefaultProps

@WithContext

@WithProps

@WithState

Contributing

Contribution guidelines for this project

License

MIT License

Keywords

jest

FAQs

Package last updated on 08 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts