mocha: "it.skip" throws an exception (when running e2e with protractor)

Recently I noticed that adding a “skip” to an “it” cause an exception, and tests are failing to run. I think it is related to some Mocha/Protractor packages mismatch, but not sure. I couldn’t find a working configuration easily.

Currently we use: Protractor: 3.0.0 Mocha: 3.0.2

Downgrading mocha to 2.4.5 solves the issue (but we miss some features and bug fixes we need). I see this was discussed here: http://stackoverflow.com/questions/38876476/running-protractor-tests-with-jenkins-throws-test-title-should-be-a-string

Any plan to fix this in future mocha versions / is it a protractor issue?

This is the error and stack trace we get:

Error: Test title should be a “string” but “function” was given instead.

at new Test (/Users/benbracha/workspace/ravelloui/ravello-ui/node_modules/mocha/lib/test.js:24:11)
    at context.it.context.specify (/Users/benbracha/workspace/ravelloui/ravello-ui/node_modules/mocha/lib/interfaces/bdd.js:84:18)

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 15 (5 by maintainers)

Most upvoted comments

Hi everyone,

For your information, I faced the same problem, so I tried to find out a solution and in my opinion it’s on the protractor side. So I create an issue on protractor github: https://github.com/angular/protractor/issues/4010. Let’s see if they agree with me 😃

Anyway, I have a quick and dirty fix (but still a fix) to this issue, by adding the following code in describe function :

describe("...", function() {
  // Start of dirty fix
  var _it = global.it;
  global.it = function() {
    if(arguments.length === 1 && typeof arguments[0] === "string")  return _it("SKIP BUGFIX -- " + arguments[0], function() {});
    else _it.apply(null, arguments);
  };
  global.it.skip = _it.skip;
  global.it.only = _it.only;
  // end of dirty fix

  it.skip("...", function() {});
});

The good news is that code makes all the suite work again.
The bad news is that code makes skipped tests behaved like sucessfull tests.

Hope it helps.

I have this issue also. Using Mocha version": “3.1.2” :

one@development ~/github/vista2poc/vista-ui $ node_modules/protractor/bin/protractor --version  
Version 4.0.11

  it.skip('all models should be deselected', function() {
    ppvPercentages.modelChoices().then(function(modelChoices) {
      modelChoices.forEach(function(modelChoice) {
        expect(modelChoice.isSelected()).to.eventually.be.false;
      });
    });
  });