lundi 19 février 2018

Why is my unit test not working?

Still getting tripped up on what and how to spy on stuff in React Components I have this function. (basically just filters a list and returns the matches when I type in a team value)

findMatchesForTeam = (team, venue) => {
        if (team) {
        console.log(team) // THIS GETS THE RIGHT TEAM (e.g. Chelsea) WHEN TESTING
          return this.props.matches.filter(t => t.homeTeam === team.name || t.awayTeam === team.name)
          .map((match) => (
            this.result(match)
          ))
        }
}

Any my test:

describe('other functions', () => {
    it('expects the matches array to have been filtered', () => {
      wrapper.instance().findMatchesForTeam('Chelsea');
      expect(matchesStub.length).to.equal(2);
    });
  });

So i'm calling the method in my component and search for Chelsea and in my matchesStub I have:

  const matchesStub = [
    {awayGoals: 1, awayTeam: "Man City", homeGoals: 1, homeTeam: "Arsenal", month: "February"},
    {awayGoals: 2, awayTeam: "Man City", homeGoals: 3, homeTeam: "Chelsea", month: "February"},
    {awayGoals: 0, awayTeam: "Chelsea", homeGoals: 0, homeTeam: "Man Utd", month: "February"}
  ];

However my test says it should be length 3 (which is the initial length) and doesn't bother filtering. the code works. the test doesn't. any help?

can post more code

Aucun commentaire:

Enregistrer un commentaire