fix(test): Throw if elements are not found #1344
fix(test): Throw if elements are not found #1344
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more what I mean. I am just a fan of less code 🤷♂️
} else { | ||
assert.exists(text, 'element with id="text" not found'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} else { | |
assert.exists(text, 'element with id="text" not found'); | |
} | |
} | |
assert.exists(text, 'element with id="text" not found'); |
@ShaunSHamilton Sorry for the lack of update on this. I had it working to where the example project and the empty project passed and failed respectively as needed. But then I tested with a React version of the project I had laying around and it fails. I rolled back to the previous code and it still fails some of the tests. It seems this PR broke it because the project passes with the old test code. I get the feeling the React conditional rendering I have in the project doesn't work with the new code. I might play around with it some more at some point, but right now I don't really have anything. |
@lasjorg The only thing that comes to my mind that could be an issue with the linked PR's changes is if the script is added before the body of the HTML. In your old React form of the project, how are you adding the test suite? |
@ShaunSHamilton No that's not it. As I said, it still passes with the old test code from before that PR. Here is a replit, you can switch the test scripts in the HTML file (current and old). |
Just to mention it, if you were unaware: Removing the return (
<>
- {quotes && hasLoaded && (
+ {quotes && (
<div id="quote-box" className={`App ${hasLoaded && 'visible'}`}>
<Quote title={quotes.author} content={quotes.content} />
<Buttons
handleClick={handleClick}
disabled={!hasLoaded}
href={getTweetLink(quotes.author, quotes.content)}
/>
</div>
)}
</>
); I also renamed |
Right but as I said it's just some code that fails with the current test that didn't with the old. It wasn't about changing the code to make it pass it was just an example of code that used to pass that now fails. I will just push what I have now because I started to mess around with it and I'm losing track of what I have tested. I added a test for the width of the container to not allow for full-width containers counting as centered. The current code should pass the example project, fail the empty project, and pass the React project with the change to the conditional code as you suggested. Having all that code before the promises just feels off to me, anyway it's what I have got so far so I might as well just push it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still causes your example app to fail, unless the hasLoaded
logic is removed from the render in App.js
.
So, I am fine with just going ahead with this for better assertion messages. Is that what we want?
As I said.
I'm still not sure what change was made in the other PR I linked to that is causing the old code to fail. But I'm not sure if it matters?
Well, the main point of this PR was to fix empty projects passing tests 6 and 7, and as later pointed out by the user in the forum, also fix the layout test for centering. If the assert messages are better as well that's just a bonus. It still feels a little awkward having all this synchronous code before the promise code, but I'm not sure what else to do. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, for baring with me, @lasjorg .
I am happy with what this accomplishes.
Something for the next reviewer: Is there any reason the 25px
leeway is too little for the testHorizontallyCentered
function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was struggling with testing this - finally figured it out. I made two suggestions.
3d84193
to
cf66407
Compare
Sorry for the delay on this. @moT01 You are right, my bad. I think when testing this I had misunderstood what the fix from the other PR was doing. For some reason, I was under the impression that it was checking for a new quote and not just re-clicking the button if the quote was the same. So I guess when I saw the tests passing I didn't think much of it. I had to rebase with main to get this to run again, so rebase > force push |
@moT01 I forgot all about this PR. Are there any other issues that need to be addressed here? A forum post that made me remember this PR. This project can be passed with an almost empty project as it is now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM @lasjorg 🎉 Sorry for the delay here - Thanks for the work on this and all your contributions 🎉
Pre-Submission Checklist
master
branch of freeCodeCamp/testable-projects-fccfix/
,feature/
, ortranslate/
(e.g.fix/signin-issue
)Type of Change
Checklist:
Description
Right now tests 6 and 7 will pass with no code for the "Build a Random Quote Machine" project. Not sure what the best way of handling this is but I think just throwing in an else block if the elements are not found should work just fine.
Forum post: https://forum.freecodecamp.org/t/build-a-random-quote-machine-bug-in-test/472095