dojo / test-extras

:rocket: Dojo 2 - set of modules to help with testing Dojo.
http://dojo.io
Other
0 stars 14 forks source link

Provide a mechanism to get widgets assigned to the properties of other widgets #74

Closed umaar closed 6 years ago

umaar commented 7 years ago

Enhancement

Imagine code like this:

v('div', {}, [
    w(Widget1, {
        key: 'widget-1',
        someProperty: w(Widget2, {
            key: 'widget-2',
            someCallback: () => {
                // business logic here!
                               return 42;
            }
        })
    })
])

From a unit test, I would like to do something like:

const widget1 = get('widget-1');
const widget2 = widget1.someProperty;
const someCallback = widget2.someCallback;

equals(someCallback(), 42);

Or something similar.

kitsonk commented 7 years ago

I am not sure of this use case...

We should test things in the way they are used, (e.g. the harness), any sub-widgets in a harnessed widgets get stubbed out (as is appropriate for a unit type of test), the only thing that remains is their properties and listeners that were rendered by the harnessed widget. The APIs of .callListener() which will execute the method (which is a property of a widget). This should trigger any business logic in the enclosing widget. These can be access by key or by index (including deep indexes).

Validating some property should be done through an expected render. We have specifically discouraged cherry picking of individual properties, because they tend to give the end developer a false sense of only positive test cases and therefore miss any unexpected properties or values. If there is a use case where cherry picking is really desired, you can use the .getRender() which will return the render structure of DNodes which can be introspected in a similar way to the above.

agubler commented 6 years ago

I don't think that this is a valid use case when testing generated VDom structures for a widget render. It is perfectly valid to assert that a widget has a property that is a "widget", similar to a render property.