-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Skipped test make all the suite failing using mocha #4010
Description
- Node Version:
6.9.1
- Protractor Version:
5.0.0
- Angular Version:
1.5.11
- Browser(s):
any
- Operating System and Version
windows 10
Hi everyone,
I have been using mocha and protractor with no problems for a few month, but after updating some dependencies (by simply runnig npm i after removing node_modules folder), it seems that a skipped test make all the suite completly failing.
So I tried again, with the latest version of both protractor and mocha but I still got the same error.
After looking for a solution to this error, I found an issue opened on mocha github : mochajs/mocha#2543
But in order to understand the problem, I tried to debug the code, and for me the problem is on the protractor side.
Here is the explanation :
-
On mocha side (how mocha works with skipped test) :
when a test is skipped it calls the "it" function only with the title of the test :
it.skip(title, func) -> it(title) -
On protractor side (in /lib/frameworks/mocha.js) :
"it" and "it.skip" (line 26 & 28) are wrapped by using the wrapped function (line 121) in order to handle asynchronous tests.
In wrapped function, it assumes that if there is only one argument, this argument should be a function, and it turns this function into an asynchronous one.- This use case is usefull for beforeEach, afterEach, after, before which first argument is always a function.
- But in case of "it.skip", it will call "it" function with only one argument (because of mocha) which is a string that will be turned into an asynchronous function and then mocha will throw an error, because mocha is expected a string.
Here is a possible solution :
before line 124 add this single line of code :
if(typeof arguments[0] === "string") return globalFn(arguments[0]);
Stacktrace :
E/launcher - Error: Error: Test
titleshould be a "string" but "function" was given instead. at new Test C:\dev\workspaces\plateforme.workspace\plateforme-frontoffice\node_modules\mocha\lib\test.js:31:11) at context.it.context.specify (C:\dev\workspaces\plateforme.workspace\plateforme-frontoffice\node_modules\mocha\lib\interfaces\bdd.js:88:18) at _wrapped (C:\dev\workspaces\plateforme.workspace\plateforme-frontoffice\node_modules\protractor\built\frameworks\mocha.js:129:14) at context.xit.context.xspecify.context.it.skip (C:\dev\workspaces\plateforme.workspace\plateforme-frontoffice\node_modules\mocha\lib\interfaces\bdd.js:108:15) at Function._wrapped [as skip] (C:\dev\workspaces\plateforme.workspace\plateforme-frontoffice\node_modules\protractor\built\frameworks\mocha.js:133:14) at Suite.<anonymous> (C:\dev\workspaces\plateforme.workspace\plateforme-frontoffice\tests\e2e\tests\login.e2e.js:84:6) at Object.create (C:\dev\workspaces\plateforme.workspace\plateforme-frontoffice\node_modules\mocha\lib\interfaces\common.js:114:19) at Object.only (C:\dev\workspaces\plateforme.workspace\plateforme-frontoffice\node_modules\mocha\lib\interfaces\common.js:79:21) at Function.context.describe.only (C:\dev\workspaces\plateforme.workspace\plateforme-frontoffice\node_modules\mocha\lib\interfaces\bdd.js:68:27) at Object.<anonymous> (C:\dev\workspaces\plateforme.workspace\plateforme-frontoffice\tests\e2e\tests\login.e2e.js:8:10)