Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This document records common issues and solutions when writing unit tests with the IoC testing framework.

Destroyed component error

Issue: If more than one event listeners were registered back to back in the test sequence, the destroyed component error would be thrown. In this example,

...

Code Block
languagejs
linenumberstrue
/** Component under test **/
fluid.defaults("fluid.tests.cat", {
    gradeNames: ["fluid.rendererComponent", "autoInit"],
});

/** Unit tests **/
...

fluid.defaults("fluid.tests.catTester", {
    gradeNames: ["fluid.test.testCaseHolder", "autoInit"],
    modules: [{
        ...
        tests: [{
            name: "Test the cat",
            sequence: [{
                listener: "{cat}.refreshView",
                priority: "last",
                event: "{catTests cat}.events.onCreate"
            }, {
                func: "fluid.tests.action"
            }, {
                listener: "fluid.tests.testDefault",
                priority: "last",
                event: "{cat}.events.afterRender"
            }]
        }]
    }]
});

None of the tests are executed

Cause 1: The tested component is instantiated before fluid.test.testCaseHolder is ready.

...