Random Quote Machine Test Case #9

Random Quote Machine Test Case #9
0

#1

Hello,

I’ve completed my Random Quote Machine project here: https://codepen.io/ttstauss/details/mGOyra/

I can’t seem to get it to pass test case #9:

    1. My quote machine should fetch the new quote’s author when the #new-quote button is clicked and display it in the #author element.

I thought it might be due to the author being the same for each quote, but I tested it with different authors and still had no luck passing.

In summary, after the component mounts or after the user clicks the new quote button, a random index is generated to select from an array of objects (each object has a quote and author prop). The appropriate props are then set to state.

Any ideas why this won’t pass?

Thanks!
Taylor


#2

It is indeed failing because of a lack of unique authors. When I look at the test code, I see:

      it(`${reqNum}. My quote machine should fetch the new quote's author when
      the #new-quote button is clicked and display it in the #author element.`,
      function() {
        let prevAuth;

        this.timeout(requestTimeout);

        prevAuth = document.getElementById('author').innerText;
        document.getElementById('new-quote').click();

        return new Promise((resolve) => {
          const intervalId = setInterval(() => {
            const newAuth = document.getElementById('author').innerText;
            if (newAuth !== prevAuth) {
              clearInterval(intervalId);
              resolve();
            }
          }, 500);
        });
      });

When I reduce the number of quote down from 17,000 to a more manageable 20 and add a unique character to the end of each, it passes.


#3

Hi Kevin,

Thanks so much for looking at this. I should’ve looked at the test code. Makes sense now.

I guess I can’t include all 275 Mitch Hedberg quotes :stuck_out_tongue:

I think I’ll just fork my origional and scale back the number of quotes. I’ll also use alternate names for each quote.

Thanks!


#4

The number of quotes wasn’t the problem, per se. It just made it difficult to debug. In the real world, you would put those quotes in a separate file, in a DB, or in an API endpoint. Of course, in the real world you would also have easy access to the testing parameters.


#5

Yeah, that makes complete sense.

Thanks for the help!