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

TypeError: test.fullTitle is not a function #79

Closed
ellerbrock opened this issue Sep 8, 2016 · 6 comments
Closed

TypeError: test.fullTitle is not a function #79

ellerbrock opened this issue Sep 8, 2016 · 6 comments

Comments

@ellerbrock
Copy link

hi there,

mochasome looks really cool.
i just tried to run it for the first time but straight run in an error :(

Environment Information

npm: 3.10.7
node: v6.5.0
mocha: 3.0.2
mochasome: 1.5.2

Problem with mochawesome: TypeError: test.fullTitle is not a function
    at cleanTest (fullstack/npm/modules/array-numbers/node_modules/mochawesome/lib/mochawesome.js:256:21)
    at arrayMap (fullstack/npm/modules/array-numbers/node_modules/mochawesome/node_modules/lodash/index.js:1406:25)
    at Function.map (fullstack/npm/modules/array-numbers/node_modules/mochawesome/node_modules/lodash/index.js:6710:14)
    at cleanSuite (fullstack/npm/modules/array-numbers/node_modules/mochawesome/lib/mochawesome.js:166:22)
    at traverseSuites (fullstack/npm/modules/array-numbers/node_modules/mochawesome/lib/mochawesome.js:143:7)
    at Runner.<anonymous> (fullstack/npm/modules/array-numbers/node_modules/mochawesome/lib/mochawesome.js:78:9)
    at emitNone (events.js:91:20)
    at Runner.emit (events.js:185:7)
    at /Users/fullstackx/.nvm/versions/node/v6.5.0/lib/node_modules/mocha/lib/runner.js:798:12
    at /Users/fullstackx/.nvm/versions/node/v6.5.0/lib/node_modules/mocha/lib/runner.js:646:9
    at next (/Users/fullstackx/.nvm/versions/node/v6.5.0/lib/node_modules/mocha/lib/runner.js:285:14)
    at Immediate.<anonymous> (/Users/fullstackx/.nvm/versions/node/v6.5.0/lib/node_modules/mocha/lib/runner.js:327:5)
    at runCallback (timers.js:574:20)
    at tryOnImmediate (timers.js:554:5)
    at processImmediate [as _immediateCallback] (timers.js:533:5)
@adamgruber
Copy link
Owner

Sample test code?

@ellerbrock
Copy link
Author

ellerbrock commented Sep 8, 2016

hi adam,

thanks for the quick response.
i had a closer look and found the problem.
one of my tests im currently working on just had an empty description:

describe('', function () { ...

In lib/mochawesome.js Line 256 you call the method test.fullTitle() which does't exist if an empty string is passed.

A simple fix could be to set the fullTitle to '(no description)' or throw an more verbose error:

  if (test.fullTitle === undefined) {
    throw new Error(chalk.bold.red(`Empty Mocha Description in Testfile: ${test.file}`));
  }

@adamgruber
Copy link
Owner

@ellerbrock I've seen this issue pop up before. I can add some checks in my code but I think the bigger problem is on mocha's end. They assume nobody would leave the description empty. I think this open PR might fix it (mochajs/mocha#2371).

In the meantime, easiest fix is to not have empty describes. ;)

@ellerbrock
Copy link
Author

ellerbrock commented Sep 9, 2016

@adamgruber jupp i saw that too yesterday that mocha did not test if its a empty string.
personally i just found a more detailed error useful. since there is already a pr for this topic i guess the future will solve it anyway :)

anyway, thanks for your good work.

issue.close();

cheers maiky

@CodingMadeEasy
Copy link

CodingMadeEasy commented Jan 28, 2017

I'm having the exact same issue but it has nothing to do with the describe. It happens when mocha.run() is called more than once.

Here's my code:


import * as path from 'path';
import * as fs from 'fs';
import * as Mocha from 'mocha';
import * as React from 'react';
import * as chokidar from 'chokidar';

let mocha: Mocha = new Mocha(
{
    reporter: 'mochawesome',
    reporterOptions:
    {
        reportDir: __dirname + '/../../public/mochawesome'
    }
});

let testsPath: string = __dirname + '/../../tests/';
let fileList: Array<string> = fs.readdirSync(testsPath).filter(file => file.split('.').pop() == 'js');
fileList.forEach (file =>
{
    console.log(file);
    mocha.addFile(path.join(testsPath, file));
});

function Invalidate()
{
    fileList.forEach (p =>
    {
        let fullPath = path.join(testsPath, p);
        p = path.resolve(fullPath);
        delete require.cache[require.resolve(p)];
    });
}

export default class Tests extends React.Component<{}, {}>
{
    componentWillMount()
    {
        //mocha.run();

        let watcher = chokidar.watch(testsPath, {persistent: true});
        watcher.on('change', path =>
        {
            console.log('change');
            Invalidate();
            mocha.run();
            //this.forceUpdate();
        });

        watcher.on('add', p =>
        {
            if (p.split('.').pop() == 'js')
            {
                console.log('add');
                Invalidate();
                mocha.addFile(p);
                mocha.run();
                //this.forceUpdate();
            }
        });
    }

    render()
    {

        return (
            <html>
                <body>
                    <iframe src='/mocha/mochawesome.html' width='100%' height='100%'/>
                </body>
            </html>
        );
    }
}

And my test code:

"use strict";
const chai_1 = require("chai");
describe('testing', function () {
    it('will equal 1', () => {
        chai_1.expect(1).to.equal(2);
    });
});

When the add or watch event is called more than once, it fails.

@tgirishkumar
Copy link

I have the same issue as @CodingMadeEasy suggested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants