mercredi 28 décembre 2016

How can I create an object/variables that are available to all tests within a module using qUnit's setup method?

I have an object and some variables that are currently being declared in each individual test that I write (not DRY at all). What I would like to do is create this object and variables in the module's setup method so that all the tests can have access to the object and variables.

This is how I have currently attempted this:

QUnit.module("Main Function Test", {

        setup: function() {

            this.controls = {
                    validCharacters : /^[0-9a-zA-Z]+$/
                    ,
                    searchResultTable : {
                        setVisible : setVisible
                    },
                    commentBoxContainer: {
                        setVisible : setVisible
                    }  
                };  

            var getValue = sinon.stub().returns(false);
            var setEnabled = sinon.spy();
       },
    });

QUnit.test("someTest that should have access to the above 'controls' object and variables" ...

When I run my tests they fail because the controls object is undefined or it can't find the variables (getValue or setEnabled).

Can someone please share what I'm doing wrong? Or the correct way to make objects and variables available to all tests within a respective module?

Aucun commentaire:

Enregistrer un commentaire