0

I want to be able to write testcases as class hierarchies in dojo/doh.

But when the tests get called they seem to be called using hitch hence looses the inherited methods.

So far I've only been able to write test cases which are independant functions, but i'd like to refractor some of the common setup into a separate method

jagguli
  • 631
  • 1
  • 7
  • 21

1 Answers1

0

There might be a better way, but I just did this by declaring a BaseTest class that contains an array of test objects.

Example:

    baseFieldViewTests: [{
        name: "Test input widget()",
        runTest: function () {
            var inputWidget = this.field.getInputWidget();
            doh.assertTrue(inputWidget.get, "Input widget has no get method");
            doh.assertTrue(inputWidget.set, "Input widget has no set method");
            doh.assertTrue(inputWidget.placeAt, "Input widget has no placeAt method");
        }
    },

Then in the subclass test I iterate through the base class tests and register them:

/**
 * Register base field view tests
 */
baseFieldViewTests = new BaseFieldViewTest().baseFieldViewTests;

for (test in baseFieldViewTests) {
    if (baseFieldViewTests[test]) {
        doh.register("component/form/text/ReadOnlyTextViewTest",
            {
                name: baseFieldViewTests[test].name,
                setUp: setUp,
                runTest: baseFieldViewTests[test].runTest,
                tearDown: tearDown
            });
    }
}

Not too elegant but it seems to work.

Mike Wilklow
  • 108
  • 1
  • 7