Giter Club home page Giter Club logo

Comments (7)

saadtazi avatar saadtazi commented on May 31, 2024

(I didn't try it... but...) did you try to create a top-level before(function() {...}) that contains your snippet (with this.browser instead of self.browser?

from grunt-mocha-webdriver.

binarykitchen avatar binarykitchen commented on May 31, 2024

I have over 50 test files here and I do not want to add that before block on the top of every test file.

What I really fancy is having a reference to the browser variable inside the require option (https://github.com/jmreidy/grunt-mocha-webdriver#require)

Also, I want to add plenty of custom chain method for all these tests files. How can I do that the most elegant way from one central place?

from grunt-mocha-webdriver.

saadtazi avatar saadtazi commented on May 31, 2024

You don't need to add it on top of every test file. Only in one file. from mochajs website:

" Note that you may also pick any file and add "root" level hooks, for example add beforeEach() outside of describe()s then the callback will run before any test-case regardless of the file its in. This is because Mocha has a root Suite with no name."

To your second question (where should you add your chain methods), personally I do it in files (grouped by types) that are loaded by that same file that contain that top-level before().

In my grunt config, I have: mochaWebdriver: {oneTarget: {src: ['before.js', ...]}}

And in before.js, I have:

...
before(function() {
  // note that this before is not in a context() or describe()
  // you can put your .on bindings here
    require('helpers/chainMethodsGroup1')(this.wd);
    require('helpers/chainMethodsGroup2')(this.wd);

})

helpers/chainMethodsGroup1:

function func1() {
}

module.exports = (function(wd) {
  wd.addPromiseMethod('func1', func1);
});

from grunt-mocha-webdriver.

binarykitchen avatar binarykitchen commented on May 31, 2024

Interesting! And where do you put the global stuff, i.E.

var chai = require('chai');
global.expect = chai.expect;

??? In before.js too or in a file defined with require?

PS: I would love to see a complete working example of your code. Do you think you could do a Gist?

from grunt-mocha-webdriver.

saadtazi avatar saadtazi commented on May 31, 2024

I put that in my "require" file:
My require file looks like this (everything is here):

/*jshint node:true*/
// Chai
var chai = require('chai');

chai.use(
  global.chaiAsPromised = require('chai-as-promised')
);
chai.should();

from grunt-mocha-webdriver.

saadtazi avatar saadtazi commented on May 31, 2024

@binarykitchen here is a gist (does not include the spec files though): https://gist.github.com/saadtazi/11070632

from grunt-mocha-webdriver.

binarykitchen avatar binarykitchen commented on May 31, 2024

Wonderful @saadtazi thanks so much!!

from grunt-mocha-webdriver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.