문제

Is it possible to ask Mockolate to dispatch binding events?

For example, given this class:

class Person {
    [Bindable]
    public var name:String;
}

I'd like the mock:

var mockPerson:Person = nice(Person);

To dispatch a propertyChangeEvent when the name field is change.

도움이 되었습니까?

해결책

As you mentioned Binding events are instances of PropertyChangeEvent, just create an instance using PropertyChangeEvent.createUpdateEvent() and use that with .dispatches().

Like so:

mock(person).setter("name").arg(anything())
    .dispatches(PropertyChangeEvent.createUpdateEvent(person, "name", oldValue, newValue));

Note however that the oldValue and newValue will need to be supplied.

I see merit in making a shortcut for this scenario seeing as binding is heavily used. The only tricky part is keeping the previous value.

If you wanted to tackle implementing this yourself I suggest looking at the Answer and Decorator classes and subclasses.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top