learn-co-curriculum / putting-it-all-together-lab

Build out a full blackjack game with React and Flux!
Other
0 stars 3 forks source link

Reducer and action tests seems to be combined #8

Closed aturkewi closed 1 year ago

aturkewi commented 7 years ago

I'm not sure this is a good idea. It seems we'd want to test them more piece by piece.

Something like this for actions:

  describe('hitUser()', function(){
    it('returns with `type` "HIT_USER"', function(){
      expect(gameActions.hitUser(this.deck, []).type).toEqual("HIT_USER")
    })
    it('returns with a `payload` with one less in the `deck`', function(){
      console.log(`The deck length is ${this.deck.length}`)
      const hitUserPayload = gameActions.hitUser(this.deck, []).payload;
      expect(hitUserPayload.deck.length).toEqual(this.deck.length - 1);
    })
    it('returns with a `payload` with one more in the `userCards`', function(){
      const userCards = [];
      const hitUserPayload = gameActions.hitUser(this.deck, userCards).payload;
      expect(hitUserPayload.aiCards.length).toEqual(userCards.length + 1)
    })
  })

Then given that the reducer is purely functional, those tests shouldn't be too bad to write.