Skip to content

Instantly share code, notes, and snippets.

@mikebridge
Last active May 17, 2017 21:15
Show Gist options
  • Save mikebridge/04f9b5dbe11469454bac291ce775839d to your computer and use it in GitHub Desktop.
Save mikebridge/04f9b5dbe11469454bac291ce775839d to your computer and use it in GitHub Desktop.
An Intellij Live template to generate a Redux component test.
//
// A TypeScript template for generating a Redux Test in IntelliJ.
// (accompanies https://gist.github.com/mikebridge/c75835cda361c5967de301995894bf30)
//
// Create: Settings -> Editor => Live Templates -> Add.
// - give it an abbreviation (e.g. "reduxtest") and a Description, and
// - Make it available in JavaScript "JSX HTML", JavaScript "Statement" and TypeScript
//
// Usage: create a file, e.g. "myTemplate.test.tsx", then type "Ctrl-J", and the abbreviation, e.g. "reduxtest".
//
import * as React from "react";
import {shallow, mount} from "enzyme";
import configureStore from "redux-mock-store";
import {Provider} from "react-redux";
import $FILENAME_PASCAL$ from "./$FILENAME_LOWER$";
const middlewares = [];
export const mockStore = configureStore(middlewares);
describe("<$FILENAME_PASCAL$ />", () => {
let initialState = {};
it("renders without crashing", () => {
const wrapper = mount(
<Provider store={mockStore(initialState)}>
<$FILENAME_PASCAL$ />
</Provider>
);
expect(wrapper.text()).toContain("Welcome to Redux");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment