Freecodecamp: Test Error Message does not indicate wrong string

Created on 9 May 2020  Â·  10Comments  Â·  Source: freeCodeCamp/freeCodeCamp


Describe your problem and how to reproduce it:

The test error messages do not indicate anything about resolve and reject’s strings.

reject should be executed when the if condition is false.
// tests completed

This may throw some people off as the message error just indicates the if statement did not fire.

Add a Link to the page with the problem:

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/complete-a-promise-with-resolve-and-reject

Test Code:

const makeServerRequest = new Promise((resolve, reject) => {
  // responseFromServer represents a response from a server
  let responseFromServer;

  if(responseFromServer) {
    resolve("We String");
  } else {  
    reject("Data String");
  }
});

Tell us about your browser and operating system:

  • Browser Name:
    Chrome
  • Browser Version:
    81.0.4044.124
  • Operating System:
    iOS 81.0.4044.124

If possible, add a screenshot here (you can drag and drop, png, jpg, gif, etc. in this box):

BBCE96E4-F281-4C08-9739-F11FCF7C0038
E1BF97DA-2F1F-4B12-8AD0-4DFBEB712881

help wanted learn

Most helpful comment

Also we have some documentation here: https://contribute.freecodecamp.org if you want to learn more.

All 10 comments

Hey @paulywill ,

I just looked at the page, and want to make sure I got this right,

Currently, the test cases only pass if "We got the data" and "Data not received" are the strings inside resolve and reject; if anything else is entered in then the tests fail.

If I'm correct, the strings don't really matter, it's just having resolve and reject inside the if and else statements with a string inside.

I just wanted to clarify what is needed before starting.

BTW, I'm a CS student who's just getting into Open Source and thought it would be awesome to contribute here! I've used freeCodeCamp in the past to help me learn the basics of Web Development, and it really has changed how I look at coding overall.

Attached are a couple of screenshots of what I tested.

Screen Shot 2020-05-09 at 2 24 41 PM
Screen Shot 2020-05-09 at 2 28 13 PM

Hey @MrKevinOConnell,

Thanks for jumping in!

The instructions do say that the string does matter, however I believe the test messages should have something pointing the user in the right direction.

Eg:
’The resolve string does not match.’

’The reject string does not match.’

Perhaps additional tests should be created for edge cases IDK 🤷‍♂️.

The file that needs to be altered for a PR should be: https://github.com/freeCodeCamp/freeCodeCamp/blob/master/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/complete-a-promise-with-resolve-and-reject.english.md

Just my two-cents: As much as it would reduce posts asking for help on the forum etc., many (if not most) of the challenges require the user to be precise, and follow instructions well. Sure, we could change many tests in other challenges, but I would much rather have the tests as is, teaching users to debug their own code.

In programming outside of tutorials, debugging is a massive portion of the process, and programmers do not always write their own tests. In my opinion, the tests are well-suit for teaching programming skills.

Just took a second look @paulywill and it makes sense now, didn't see the part that specified what the strings had to be.

I'll probably just add a couple of tests to check for what the strings are inside of resolve/reject and change the test messages depending on which ones were passed.

BTW, if you don't mind me asking, why do you guys have all of your files in Markdown? I'm just curious for the sake of learning.

BTW, if you don't mind me asking, why do you guys have all of your files in Markdown? I'm just curious for the sake of learning.

That’s a question @raisedadead or @RandellDawson or some of the moderators could artIculate a better answer, but I think the theory is that markdown is an easy to read input for feeding the curriculum engine/logic.

BTW, if you don't mind me asking, why do you guys have all of your files in Markdown? I'm just curious for the sake of learning.

TL;DR: Markdown is easy on editing.

We used to have a json object (schema) for the challenges in the earlier days, but ever since we moved to Gatsby - A static site generator, we started using markdown.

It is easy for contributors to edit a text file. More often than not when making a quick contribution, you do not need to know how the underlying infra works, because maybe you are changing the instructions a little bit, fixing a typo, you get the idea.

We wrote a custom parser (and a schema that it needs to be compliant with) to get the content out of the markdown and build the HTML pages (which is implemented as a Gatsby plugin of course).

You are welcome to dig into the client package to learn how it works.

P.S: All questions are welcome, do not be shy :)

That makes a lot of sense @raisedadead thanks for the response,

I have a couple more questions actually If you don't mind me asking,

Since the challenges are made using Gatsby, how do you guys test your code? Do you make your own site and run it on there? Or do you use extensions on whatever IDE/text editor you use?

Also, what does YML mean? I'm assuming YAML, but I honestly don't know, I think however that If I know what that means I can figure it out.

Here's what I have so far:

`

tests:
  - text: <code>resolve</code> should be executed when the <code>if</code> condition is <code>true</code>.
    testString: assert(removeJSComments(code).match(/if\s*\(\s*responseFromServer\s*\)\s*{\s*resolve\s*\(\s*('|"|`)\1\s*\)(\s*|\s*;\s*)}/g));
  - text: <code>reject</code> should be executed when the <code>if</code> condition is <code>false</code>.
    testString: assert(removeJSComments(code).match(/}\s*else\s*{\s*reject\s*\(\s*('|"|`;
  - text: ’The <code> resolve </code> string does not match.’
    testString: assert(removeJSComments(code).match(/if\s*\(\s*responseFromServer\s*\)\s*{\s*resolve\s*\(\s*('|"|`)We got the data\1\s*\)(\s*|\s*;\s*)}/g));
  - text: ’The <code> reject </code> string does not match.’
    testString: assert(removeJSComments(code).match(/}\s*else\s*{\s*reject\s*\(\s*('|"|`)Data not received\1\s*\)(\s*|\s*;\s*)}/g));

`
What I want to do is change the first two tests to just resolve and reject with empty strings inside, then have the last two be with the correct string inside.

These are probably very simple questions but I think they would help me out a lot as I contribute more this summer!

@MrKevinOConnell have you made a PR yet?

When you do put the PR # in this thread so we can test your tests.

If you need any help with this let me know.

EDIT:
Yes, YML stands for YAML files (yet another markup language).

If you read the instruction on installing FreeCodeCamp locally there should be instructions for testing locally as well.

To test curriculum:
npm run test:curriculum

To test everything:
npm run test

Check out package.json for all the commands for the project.

Also we have some documentation here: https://contribute.freecodecamp.org if you want to learn more.

I'm working on setting up my repo locally and getting a basic idea of the codebase, as I've never worked with YAML; if anyone else wants to fix this issue don't hesitate! I can work on something else.

Like I said I'm new to open source so all of this stuff is new to me, apologies for me taking this long, I will be a lot more productive once I have more time on my hands.

Was this page helpful?
0 / 5 - 0 ratings