Unspecified AssertionError

Hello, I’ve decided to start contributing to the open source code base, I picked an issue, wrote my first line of code, ran the rest for it, and it failed one of the tests. Here is the error:

  916 passing (19s)
  1 failing

  1) Check challenges
       Check challenges (english)
         basic-javascript
           Iterate Through an Array with a For Loop
             Check tests against solutions
               Solution 1 must pass the tests:
     Test text: <p>You should be using the elements of <code>myArr</code> to update <code>total</code>.</p>
  AssertionError: Unspecified AssertionError
      at eval (eval at _callee$ (http://127.0.0.1:8080/js/test-evaluator.721fcd3ab20c7625dd0d.js:2:224375), <anonymous>:33:1)
      at _callee$ (http://127.0.0.1:8080/js/test-evaluator.721fcd3ab20c7625dd0d.js:2:224375)
      at f (http://127.0.0.1:8080/js/test-evaluator.721fcd3ab20c7625dd0d.js:2:197111)
      at Generator._invoke (http://127.0.0.1:8080/js/test-evaluator.721fcd3ab20c7625dd0d.js:2:196899)
      at Generator.next (http://127.0.0.1:8080/js/test-evaluator.721fcd3ab20c7625dd0d.js:2:197540)
      at n (http://127.0.0.1:8080/js/test-evaluator.721fcd3ab20c7625dd0d.js:2:217790)
      at s (http://127.0.0.1:8080/js/test-evaluator.721fcd3ab20c7625dd0d.js:2:217993)
      at http://127.0.0.1:8080/js/test-evaluator.721fcd3ab20c7625dd0d.js:2:218052
      at new Promise (<anonymous>)
      at http://127.0.0.1:8080/js/test-evaluator.721fcd3ab20c7625dd0d.js:2:217933

Here is the content under the # --hints-- heading:

# --hints--

`total` should be declared and initialized to 0.

```js
assert(code.match(/(var|let|const)\s*?total\s*=\s*0.*?;?/));
```

`total` should equal 20.

```js
assert(total === 20);
```

You should use a `for` loop to iterate through `myArr`.

```js
assert(/for\s*\(/g.test(code) && /myArr\s*\[/g.test(code));
```

You should not attempt to directly assign the value 20 to `total`.

```js
assert(!__helpers.removeWhiteSpace(code).match(/total[=+-]0*[1-9]+/gm));
```

You should be using the elements of `myArr` to update `total`.

```js
assert(!__helpers.removeWhiteSpace(code).match(/total[+=-]+\S*myArr\[\w[\w\d]*\]/gm));
```

The last assertion and the hint above it is what I added:

You should be using the elements of `myArr` to update `total`.

```js
assert(!__helpers.removeWhiteSpace(code).match(/total[+=-]+\S*myArr\[\w[\w\d]*\]/gm));
```

It seems like the lines I added are formatted the same way as the other assertions, so I’m not sure why that test failed.

Note: the issue this is supposed to be for is Challenge: Iterate through an array with a for loop (Make test and requirements stricter) #45041 (I know there is already a PR for this issue, that happened while I was still trying to figure out how this all works, but I still want to work through this problem in order to understand what’s going on before moving on to a different issue.)

Hey again :wave:

Just to say, this attitude, and practice of yours is admirable, and will help you immensely as a developer! Kudos.

I know there is already a PR for this issue, that happened while I was still trying to figure out how this all works, but I still want to work through this problem in order to understand what’s going on before moving on to a different issue.


One thing I like doing with these tests is to write specified assertions, because the output is friendlier:

assert.match(!__helpers.removeWhiteSpace(code), /total[+=-]+\S*myArr\[\w[\w\d]*\]/gm);

Otherwise, be sure you are getting what you expect with your Regex. Some tips:

  1. Try out https://regex101.com
  2. We recommend not writing Regex tests, when possible, because it is very difficult to account for all correct permutations of Camper code.
  3. I suggest removing the g flag in your regex, because it is needlessly causing a negative performance impact.
  4. Most specifically, if you are removing the whitespace, what do you expect \S* to not match?

Hope this helps

1 Like

ooohhh, I see now, the line that says solution 1 must pass the tests. I was focusing too much on the test text line thinking that was the problem. I haven’t solved it yet, but I now know at least what the actual issue is. Thanks for your help! ^^

EDIT: the issue was the negation before __helper as i thought the ! it was part of the variable name for some reason.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.