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

Created on 16 Oct 2016  路  15Comments  路  Source: mochajs/mocha

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)
needs-feedback stale unconfirmed-bug

All 15 comments

will need to see code to help

@boneskull do you mean code example?
It happens if one of my tests has a "skip" on it.

e.g.

describe('Some context', function() {

    it.skip('some test we would like to skip', function() {
                // a failing test
     });

});

@benbracha The commit 08bf74d8440b811e42bf4b8150a4977a05472c9a could have fixed the issue, if any due to wrong reference of it. Did you, by any chance, try upgrading to latest mocha instead of downgrading?

Thanks @vivganes , I can try. What version of Mocha should I upgrade to?

latest

@vivganes I have some issues to run the tests now, I'll retry again later.
But IIUC the commit you sent was already existing in mocha version I tried which failed (3.0.2). Isn't it?

@benbracha you are right. The commit is present in 3.0.2 also. My bad! I will try to run your version combination and see what i can find out. Do you by any chance have any open source repo that you could point me to, where the issue is reproducible?

I have this old repo for reproducing other issue we had (.only in tests didn't work) with similar stack.
https://github.com/benbracha/protractor-test-app
Maybe you can try clone it and upgrade packages to relevant versions, and try out.

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;
      });
    });
  });

I attempted to reproduce this from @benbracha's repo. I upgraded to latest Mocha, and could not reproduce the problem.

@dman777 Can you provide an example reproducible case?

Sorry, I don't think I can provide anything real time. Other than the versions I posted, here is my protractor config:

```javascriptexports.config = {
framework: 'mocha',
directConnect: true,
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
specs: ['./stories/*.js'],
onPrepare: function() {
expect = require("chai").use(require("chai-as-promised")).expect;
},
mochaOpts: {
enableTimeouts: false,
reporter: "spec",
slow: 5000
},
capabilities: {
browserName: 'chrome'
}
}


I downgraded Mocha to `2.4.5` and it resolved my issue. 

Here is my node info:

one@localhost ~/github/vista2poc/vista-ui $ nvm list
-> v7.1.0
default -> node (-> v7.1.0)
node -> stable (-> v7.1.0) (default)
stable -> 7.1 (-> v7.1.0) (default)
iojs -> N/A (default)
lts/* -> lts/boron (-> N/A)
lts/argon -> v4.6.2 (-> N/A)
lts/boron -> v6.9.1 (-> N/A)


one@localhost ~/github/vista2poc/vista-ui $ npm --version
3.10.9
```

protractor: 4.0.11
mocha: 3.1.2
here is the key stacktrace:

Error: Error: Test title should be a "string" but "function" was given instead.
at new Test (node_modulesmochalibtest.js:26:11)
at context.it.context.specify (node_modulesmochalibinterfacesbdd.js:86:18)
at node_modulesselenium-webdrivertestingindex.js:95:14
at context.xit.context.xspecify.context.it.skip (node_modulesmochalibinterfacesbdd.js:105:15)
at Function.skip (node_modulesselenium-webdrivertestingindex.js:98:14)

mocha skip calls it with 1 argument: title.
The selenium wrapper, (node_modules/selenium-webdriver/testing/index.js:95) uses the 1 argument as function, making it async. Result: call it with function only.

in selenium webdriver 3 its fixed:
https://github.com/SeleniumHQ/selenium/issues/2127
but protractor uses the 2.53 version
we need to wait until protractor beta is released

FYI Protractor 4.0.14 still have the problem.

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 am a bot that watches issues for inactivity.
This issue hasn't had any recent activity, and I'm labeling it stale. In 14 days, if there are no further comments or activity, I will close this issue.
Thanks for contributing to Mocha!

Was this page helpful?
0 / 5 - 0 ratings