Collin Brewer
Collin Brewer

Reputation: 11

Is there a way to have nested tests in DalekJS?

I'd like to be able to keep my tests as DRY as possible and I'm doing a lot of redundant stuff when navigating around with Dalek.

Is there a way to execute a test from within another test, and more specifically, keep the test going from where the previous left off?

For example:

test
   .runTestWithName("login") // opens url, fills out form, clicks submit
   .assert.exists("#create-new-todo-button")
   .done();

I've tinkered with some stuff but it had unexpected results.

Thanks in advance.

Upvotes: 1

Views: 157

Answers (1)

eyalzek
eyalzek

Reputation: 255

You can keep the repeated code on a separate file, lets call it helper.js:

module.exports = {
    "login": function(test) {
        test.open(some_url)
            .assert.exists("some_selector", "verify that some_selector exists")
    }
};

Then on your main file, lets call it index.js, you can require that module:

var helper = require("./helper") // path is realtive, this is assuming that both files are in the same folder

module.exports = {
    "my main test": function(test) {
        helper.login(test);
        ** some more tests **
        .done();
    }
}

Also check this url out, it has some examples: https://github.com/asciidisco/jsdays-workshop/tree/8-dry/test/dalek

Upvotes: 1

Related Questions