Created
March 11, 2019 22:17
-
-
Save cladley/b89cec085dce382d74797113f7d933d0 to your computer and use it in GitHub Desktop.
Integration tests, testing action and reducer working together
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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