Giter Club home page Giter Club logo

internet-series-database-client's Introduction

πŸ‘‹ Hi there, I'm Emily!

Python | JavaScript | TypeScript | Java | R  

internet-series-database-client's People

Contributors

emilydaykin avatar

Stargazers

 avatar

Watchers

 avatar

internet-series-database-client's Issues

Backend register error not appearing in Jest DOM screen reader

Inside the "Handle Register Submit" function's catch block:

if (err.response) {
  // This comes from the backend
  setErrorMessage(err.response.data.message);
} else {
  // This comes from the front end
  // VERY HACKY (this makes the test pass and won't appear to user)
  setErrorMessage('Undefined error message (from backend).');
}

err.response.data.message = 'Username already taken.', which is also displayed to the user in the UI (great), but the Jest DOM sees 'Undefined error message (from backend).'... so how do I assert that the user DOES in fact see the correct error message 'Username already taken.'???

Screenshot 2022-06-04 at 17 11 01

Mock axios post request has no calls

axios.post = jest.fn();
axios.post();
...
console.log(axios.post.mock);

returns:

{
  calls: [ [] ],
  instances: [ { get: [Function], post: [Function] } ],
  invocationCallOrder: [ 1 ],
  results: [ { type: 'return', value: undefined } ],
  lastCall: []
}

Screenshot 2022-06-04 at 17 26 49

Expecting http://localhost:8001/api/login to be in the calls.

Integration test failing: Assert carousels are displayed (calling two jest mock api calls)

test('Assert carousels are displayed if user has favourited series', async () => {
  jest.mock('axios');

  axios.get.mockImplementation((url) => {
    switch (url) {
      // all series
      case '/api/series':
        return Promise.resolve({ data: mockSeriesData });
      // favourites
      case `/api/users/testUser000`:
        return Promise.resolve({ data: mockSeriesData[0] });
      default:
        return Promise.reject(new Error('not found'));
    }
  });

  await act(async () => {
    render(
      <BrowserRouter>
        <UserProfile />
      </BrowserRouter>
    );
  });

  await waitFor(() => expect(axios.get).toHaveBeenCalled());                                         // PASSES

  axios.get('/api/series').then((resp) => expect(resp.data).toEqual(mockSeriesData));                // PASSES

  axios.get('/api/users/testUser000').then((resp) => expect(resp.data).toEqual(mockSeriesData[0]));  // PASSES

  const seriesCard = screen.queryByText(mockSeriesData[0].name);
  expect(seriesCard).toBeInTheDocument();                                             // FAILS!!!!!!!!!!!!!!!!

  const noFavouritesMessage = screen.queryByText(/no favourites yet/i);
  expect(noFavouritesMessage).not.toBeInTheDocument();                                // FAILS!!!!!!!!!!!!!!!!
  const noRecommendationsMessage = screen.queryByText(/no recommendations yet/i);
  expect(noRecommendationsMessage).not.toBeInTheDocument();                           // FAILS!!!!!!!!!!!!!!!!

  const carouselCards = screen.getAllByRole('link', { className: /card/i });
  // at least 1 card for favourites, 1 for recommendations
  expect(carouselCards.length).toBeGreaterThanOrEqual(2);                             // FAILS!!!!!!!!!!!!!!!!
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.