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

Need a way to access chai's "should" object #327

Closed
brettle opened this issue Apr 30, 2015 · 8 comments
Closed

Need a way to access chai's "should" object #327

brettle opened this issue Apr 30, 2015 · 8 comments

Comments

@brettle
Copy link

brettle commented Apr 30, 2015

[Edited to reflect that the problem occurs in a meteor velocity testing context.]

When using cucumber-js within meteor velocity, chai.should() is automatically called but there is currently no way to access the object that it returns. That object is normally used like this:

should = chai.should(); 
should.exist(var_which_could_be_undefined);

One solution would be to make the object returned by chai.should() available as global.should.

@goofballLogic
Copy link

@brettle Can you post a larger chunk of code showing what you are trying to do? I use chai should with cucumber.js all the time. (Mornag sends his greetings.)

@brettle
Copy link
Author

brettle commented Apr 30, 2015

You are probably using the 'should' property like this:

actual.should.equal(expected);

That works fine if 'actual' exists. However to test if it exists Chai provides the should object returned by chai.should() which can be used like in my previous example.

@goofballLogic
Copy link

I use it like this:

var should = require( "chai" ).should();

module.exports = function() {

    this.World = new (require( "../support/world.js" ))().World;

    this.Around = require( "../support/around_hooks" );

    this.Given(/^I am on the home page$/, function ( callback ) {

        this.visit( "http://localhost:3000/", callback );

    } );

    this.When(/^I fetch the body text$/, function (callback) {
        // Write code here that turns the phrase above into concrete actions
        this.evaluate( function() { return window.document.body.textContent; }, function( result ) {

            this.bodyText = result;
            callback();

        }.bind( this ) );

    });

    this.Then(/^I should find "([^"]*)"$/, function (expected, callback) {

        should.exist( this.bodyText );
        this.bodyText.should.equal( expected );
        callback();

    });

};

@brettle
Copy link
Author

brettle commented Apr 30, 2015

Sorry for not being clear. I'm using cucumber-js via meteor-cucumber and at least in that context, require('chai') fails unless you create and add a separate meteor package which uses Npm.depends() to bring in the chai module. I created this issue at Sam Hatoum's request based on a discussion on the meteor forums. Perhaps require('chai') works fine outside the meteor context?

@goofballLogic
Copy link

Yeah, I use it all the time. As far as I know chai isn't a direct dependency of cucumber.js - you have to require it yourself. You can pull in any assertion library you want for a standard node.js project.

@jbpros
Copy link
Member

jbpros commented Jun 12, 2015

I don't really understand what you expect from Cucumber here. It is agnostic on assertion/testing libraries. If a require() to your assertion module doesn't resolve, it's because you need to install that package (you can't require a dependency of a dependency).

One solution I see is xolvio:cucumber adding should to the global namespace.

Please reopen if you think there's something we can do on Cucumber's side.

@jbpros jbpros closed this as completed Jun 12, 2015
@brettle
Copy link
Author

brettle commented Jun 12, 2015

Sorry for the confusion. It looks like I should have filed this issue with xolvio/cuke-monkey (now xolvio/chimp). It appears to be fixed there at this point.

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants