JS Windowing System Test Bug

This should be passing but is not. Ran it on CodePen and is ok. Could this be a bug in the test? Thank you.

CODE:

class Size{
  constructor(width = 80, height = 60){
    this.width = width;
    this.height = height;
  }
  resize(newWidth,newHeight){
    this.width = newWidth < 1 ? 1 : newWidth;
    this.height = newHeight < 1 ? 1 : newHeight;
  }
}

ERROR:

TypeError: _windowingSystem.Size is not a constructor

We don’t have the full picture here. What code did you use to test your Size class in CodePen? Which test on Exercism failed?

I think there is no problem with it. I have executed it in the browser’s console, and there are no errors.

For anyone else running into this issue, the class or constructor function needs to be exported, otherwise you will get this error. Just had to debug it myself.

Okay, so here’s what I think is happening and why there is confusion:

As @Bargs has noticed, the class that you define for this exercise, as well as the functions, need to be exported for the test runner to be able to see them and run the tests against them.

Usually the stub we provide in the beginning includes some scaffolding and the proper names of things to be exported, but this one doesn’t. It does however have a comment that reminds you to export your class but i assume that got deleted and forgotten somewhere in the process of solving the exercise.

@SleeplessByte Any idea if the stub is empty on purpose or has it just been forgotten? Do we need to add some scaffolding?


Also, @Bargs if you’re exporting your constructor and each method on their own, that’s not the best way to do it since you lose some of the benefits of the class (not that it’s obvious in this exercise). Instead, export the whole class and it should be fine.

1 Like

Yeah, it was on purpose. I think it’s fine. It explicitly says to export it.
We may need a new exercise in-between to “teach” this better though!

1 Like