Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test suite exercise difference of squares broken? #672

Closed
marge2312 opened this issue Apr 29, 2019 · 2 comments
Closed

test suite exercise difference of squares broken? #672

marge2312 opened this issue Apr 29, 2019 · 2 comments
Labels
bug 🐛 Something isn't working question 🤔

Comments

@marge2312
Copy link

Hello diligent programmers,

yesterday i downloaded the exercise "difference-of-squares" in javascript track.
i made 'npm install', created a file called 'difference-of-squares.js' and tried to run the test-suite with 'npm test'.
Unfortunately i encountered the following error:


- Test suite failed to run
    
        A "describe" callback must not return a value.
        Returning a value from "describe" will fail the test in a future version of Jest.
    
          1 | import { Squares } from './difference-of-squares';
          2 | 
        > 3 | describe('difference-of-squares', () => {
            | ^
          4 |   const squares1 = new Squares(1);
          5 |   const squares5 = new Squares(5);
          6 |   const squares100 = new Squares(100);
    
          at addSpecsToSuite (node_modules/jest-jasmine2/build/jasmine/Env.js:522:17)
          at Object.describe (difference-of-squares.spec.js:3:1)

anybody any ideas? i'm totally stuck... :(

best regards,
Marge

@SleeplessByte
Copy link
Member

Hi there @marge2312,

First check if your test suite looks like the code block below. If it doesn't, your test file might be out of date. This can happen if per chance you've downloaded it a while ago (maybe by accident) and we have since updated the test suite. In this case, browse to the solution page (exercism.io/tracks/ -> javascript -> difference of squares) and press the update exercism button. Download the exercise again.

import { Squares } from './difference-of-squares';

describe('difference-of-squares', () => {
  const squares1 = new Squares(1);
  const squares5 = new Squares(5);
  const squares100 = new Squares(100);

  describe('Square the sum of the numbers up to the given number', () => {
    xtest('square of sum 1', () => {
      expect(squares1.squareOfSum).toBe(1);
    });

    xtest('square of sum 5', () => {
      expect(squares5.squareOfSum).toBe(225);
    });

    xtest('square of sum 100', () => {
      expect(squares100.squareOfSum).toBe(25502500);
    });
  });

  describe('Sum the squares of the numbers up to the given number', () => {
    xtest('sum of squares 1', () => {
      expect(squares1.sumOfSquares).toBe(1);
    });

    xtest('sum of squares 5', () => {
      expect(squares5.sumOfSquares).toBe(55);
    });

    xtest('sum of squares 100', () => {
      expect(squares100.sumOfSquares).toBe(338350);
    });
  });

  describe('Subtract sum of squares from square of sums', () => {
    xtest('difference of squares 1', () => {
      expect(squares1.difference).toBe(0);
    });

    xtest('difference of squares 5', () => {
      expect(squares5.difference).toBe(170);
    });

    xtest('difference of squares 100', () => {
      expect(squares100.difference).toBe(25164150);
    });
  });
});

If everything looks right, there is an outstanding bug with Jest that sometimes reports any error outside of the test suite as "describe should not return a value". There was another bug that was recently merged but not yet released.

The expected error looks like this:

 FAIL  ./difference-of-squares.spec.js
  ● Test suite failed to run

    Cannot find module './difference-of-squares' from 'difference-of-squares.spec.js'

    However, Jest was able to find:
        './difference-of-squares.spec.js'

    You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js', 'json', 'jsx', 'ts', 'tsx', 'node'].

    See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string

    > 1 | import { Squares } from './difference-of-squares';
        | ^
      2 | 
      3 | describe('difference-of-squares', () => {
      4 |   const squares1 = new Squares(1);

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:229:17)
      at Object.<anonymous> (difference-of-squares.spec.js:1:1)

This error can be fixed by creating the file difference-of-squares.js. Once you create that file, the error should look like the following. NOTE you can see the describe warning here, but it's not what caused the test to fail. This will be fixed in a later version of jest as described above.

 FAIL  ./difference-of-squares.spec.js
  difference-of-squares
    × encountered a declaration exception (3ms)

  ● difference-of-squares › encountered a declaration exception

    TypeError: _differenceOfSquares.Squares is not a constructor

      2 | 
      3 | describe('difference-of-squares', () => {
    > 4 |   const squares1 = new Squares(1);
        |                    ^
      5 |   const squares5 = new Squares(5);
      6 |   const squares100 = new Squares(100);
      7 | 

      at Suite.Object.<anonymous>.describe (difference-of-squares.spec.js:4:20)      at Object.describe (difference-of-squares.spec.js:3:1)

  console.log node_modules/jest-jasmine2/build/jasmine/Env.js:520
      ● Test suite failed to run

        A "describe" callback must not return a value.
        Returning a value from "describe" will fail the test in a future version of Jest.

          1 | import { Squares } from './difference-of-squares';
          2 | 
        > 3 | describe('difference-of-squares', () => {
            | ^
          4 |   const squares1 = new Squares(1);
          5 |   const squares5 = new Squares(5);
          6 |   const squares100 = new Squares(100);

          at addSpecsToSuite (node_modules/jest-jasmine2/build/jasmine/Env.js:522:17)
          at Object.describe (difference-of-squares.spec.js:3:1)

In this case, the file is lacking an export

+ export class Squares {
+ 
+ }

It should now "run" correctly.

@SleeplessByte SleeplessByte added question 🤔 bug 🐛 Something isn't working labels Apr 29, 2019
@marge2312
Copy link
Author

thanks so much! 👍
the lacking export was the problem! 🤔😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working question 🤔
Projects
None yet
Development

No branches or pull requests

2 participants