Skip to content

Instantly share code, notes, and snippets.

@cladley
Created March 11, 2019 22:17
Show Gist options
  • Save cladley/b89cec085dce382d74797113f7d933d0 to your computer and use it in GitHub Desktop.
Save cladley/b89cec085dce382d74797113f7d933d0 to your computer and use it in GitHub Desktop.
Integration tests, testing action and reducer working together
import { storeFactory } from "../test/testUtils";
import { guessWord } from "./actions";
describe("guessWord action dispatcher", () => {
const secretWord = "party";
const unsuccessfulGuess = "train";
describe("no guessed words", () => {
let store;
const initialState = { secretWord };
beforeEach(() => {
store = storeFactory(initialState);
});
it("updates state correctly for unsuccessful guess", () => {
store.dispatch(guessWord(unsuccessfulGuess));
const newState = store.getState();
const expectState = {
...initialState,
success: false,
guessedWords: [
{
guessedWord: unsuccessfulGuess,
letterMatchCount: 3
}
]
};
expect(newState).toEqual(expectState);
});
xit("update state correctly for a successful guess", () => {
store.dispatch(guessWord(secretWord));
const newState = store.getState();
const expectState = {
...initialState,
success: true,
guessedWords: [
{
guessWord: secretWord,
letterMatchCount: 5
}
]
};
expect(newState).toEqual(expectState);
});
});
xdescribe("some guessed words", () => {
const guessedWords = [{ guessedWord: "agile", letterMatchCount: 1 }];
const initialState = { guessedWords, secretWord };
let store;
beforeEach(() => {
store = storeFactory(initialState);
});
it("updates state correctly for unsuccessful guess", () => {
store.dispatch(guessWord(unsuccessfulGuess));
const newState = store.getState();
const expectedState = {
secretWord,
success: false,
guessedWords: [
...guessedWords,
{ guessWord: unsuccessfulGuess, letterMatchCount: 3 }
]
};
expect(newState).toEqual(expectedState);
});
it("update state correctly for a successful guess", () => {
store.dispatch(guessWord(secretWord));
const newState = store.getState();
const expectedState = {
secretWord,
success: true,
guessedWords: [
...guessedWords,
{ guessWord: secretWord, letterMatchCount: 5 }
]
};
expect(newState).toEqual(expectedState);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment