Freecodecamp: React PropTypes Challenge Unclear

Created on 8 Jul 2020  路  6Comments  路  Source: freeCodeCamp/freeCodeCamp

https://www.freecodecamp.org/learn/front-end-libraries/react/use-proptypes-to-define-the-props-you-expect

In the instructions and unit tests are ambiguous with the word "required".

It states:
"The Items component should include a propTypes check that requires quantity to be a number."

This is unclear as "requires" could mean that this check just simply needs to exist for the test to pass or that quantity should be a number that is required.

I suggest either changing the above wording, or adding an additional unit test:
"The Items component should include a quantity propType that is required."

first timers only learn

Most helpful comment

I cannot think of a more effective testString, personally. But for the test text, perhaps something like "The Items component should include a propTypes check to require a value for quantity and ensure that value is a number."

All 6 comments

image

I think the lesson instructions are pretty clear, but I do agree that the test case wording is ambiguous. I would propose that the test message be edited to mirror this instruction.

I do not think the test text should just be a duplicate of the instruction. That would be redundant. Instead, we need to rewrite the text to reflect was is being tested. See below for the current testString prettified:

assert((function() {
  const noWhiteSpace = getUserInput('index').replace(/ /g, '');
  return noWhiteSpace.includes('quantity:PropTypes.number.isRequired') && noWhiteSpace.includes('Items.propTypes=');
})());

The important part of the test is in the return statement. We are validating that we see the text "quantity:PropTypes.number.isRequired" and "Items.propTypes='" after removing whitespaces from the code. There probably is a better testString that could be written also.

I cannot think of a more effective testString, personally. But for the test text, perhaps something like "The Items component should include a propTypes check to require a value for quantity and ensure that value is a number."

I agree that the text should be updated. I just got caught up by the unclear instructions. The way it is, I thought that what was 'required' was that quantity be a number. It doesn't suggest to me that a quantity is required.

Opening this PR for contributions. The test text should be changed to:

The Items component should include a propTypes check to require a value for quantity and ensure that its value is a number.

Was this page helpful?
0 / 5 - 0 ratings