Rooster Regulation (TDD with Mocha) - 2 passing 2 pending - Please help!

Hello everyone,

I’m dealing with the project Rooster Regulation and when I run the test I get two passing and two pending: no idea why. I already checked it with the video, but it seems I’m not able to find the error! I’m thankful for and advice!

This is my code:

const assert = require('assert');

const Rooster = require('../index');

describe('Rooster', () => {

  describe('.announceDawn', () => {

    it('returns a rooster call', () => {

      // Setup

      const expected = 'cock-a-doodle-doo!';

      // Exercise

      const result = Rooster.announceDawn();

      // Verify

      assert.ok(result === expected);

    });

  });

  describe('.timeAtDawn', () => {

    it('returns its argument as a string', () => {

      // Setup

      const inputNumber = 7; 

      const expected = '7'

      // Exercise

      const result = Rooster.timeAtDawn(inputNumber); 

      // Verify

      assert.strictEqual(result, expected);

    });

    it('throws an error if passed a number greater than 23'), () => {

      // Setup

      const inputNumber = 26;

      const expected = RangeError; 

      //Verify

      assert.throws(() => { 

        Rooster.timeAtDawn(inputNumber); // Exercise

        }, expected)

 };

 it('throws an error if passed a number less than 0'), () => {

      // Setup

      const inputNumber = -1;

      const expected = RangeError; // I was not sure about this. I checked it in the video!

      //Verify

      assert.throws(() => { 

        Rooster.timeAtDawn(inputNumber); // Exercise

        }, expected)

 };

});

});

<3

Hello, this is one of those bugs that can be very difficult to debug because it’s not generating any syntax errors, so it can lead you to believe it’s a logic issue. Once you know to look out for it, it gets a lot easier to spot in the future.

One big clue is that 2 of them are Pending, rather than Passing or Failing, which indicates that your code for the test isn’t even running.

I suggest focusing on a couple snippets of your code to make it easier. One snippet will be a test that is working, another will be one that isn’t.

// This one is working and showing the passing test
    it('returns its argument as a string', () => {
      // Setup
      const inputNumber = 7;
      const expected = '7'
      // Exercise
      const result = Rooster.timeAtDawn(inputNumber);
      // Verify
      assert.strictEqual(result, expected);
    });
// This one shows the test is pending, despite you having a test
    it('throws an error if passed a number greater than 23'), () => {
      // Setup
      const inputNumber = 26;
      const expected = RangeError;
      //Verify
      assert.throws(() => {
        Rooster.timeAtDawn(inputNumber); // Exercise
      }, expected)
    };

Since the non-working snippet is showing as Pending instead of Passed or Failed, we know that the code of the test isn’t being executed. Can you see any reasons why or any key differences between these two code blocks?

Click for another hint

Let’s focus in even more. We know the code of the test isn’t running because of the Pending status, so I’ll remove that part of the code to help isolate more. We know that the arrow function isn’t being called.

    it('returns its argument as a string', () => {
      // code that runs for the test
    });
    it('throws an error if passed a number greater than 23'), () => {
      // code that isn't running for the test
    };

Have you spotted any key differences?

Click for another hint

Is the arrow function being passed to the it() function as the 2nd argument? It is for the working one, but not for the test that isn’t working.

Click for another hint

Look at the differences in the parentheses in them. You aren’t passing the callback to the it() function because you have a parenthesis that’s making the complete call it('throws an error if passed a number greater than 23') The test never gets passed to it() so it never gets called.

You’ll need to remove that ) and move it to after the end-curly brace of the arrow function. Notice that’s how you’re doing it for the one that is working.

3 Likes

Amazing. Thank you for your great and patient explanation! <3

2 Likes