mockolate icon indicating copy to clipboard operation
mockolate copied to clipboard

Expectation counts wrong the method calls

Open inner-peace opened this issue 10 years ago • 0 comments

Hi Drew

I try to use expect() instead received() and find the problem (received() works properly). Clean test below

package {
import flash.events.Event;
import flash.events.EventDispatcher;

import mockolate.arg;
import mockolate.expect;
import mockolate.runner.MockolateRule;

import org.hamcrest.core.anything;
import org.hamcrest.object.hasProperty;

public class FoobarTest {

    [Rule]
    public var rule:MockolateRule = new MockolateRule();

    [Mock]
    public var ed:EventDispatcher;

    [Test]
    public function works():void {
        expect(ed.dispatchEvent(arg(anything()))).twice();
        expect(ed.dispatchEvent(arg(hasProperty('type', '1'))));
        expect(ed.dispatchEvent(arg(hasProperty('type', '2'))));

        ed.dispatchEvent(new Event('1'));
        ed.dispatchEvent(new Event('2'))
    }

    [Test]
    public function notWorks():void {
        expect(ed.dispatchEvent(arg(anything()))).thrice();
        expect(ed.dispatchEvent(arg(hasProperty('type', '1')))).twice();
        expect(ed.dispatchEvent(arg(hasProperty('type', '2'))));

        ed.dispatchEvent(new Event('1'));
        ed.dispatchEvent(new Event('1'));
        ed.dispatchEvent(new Event('2'))
    }

    [Test]
    public function butAgainWorks():void {
        expect(ed.dispatchEvent(arg(hasProperty('type', '1')))).twice();
        expect(ed.dispatchEvent(arg(hasProperty('type', '2'))));

        ed.dispatchEvent(new Event('1'));
        ed.dispatchEvent(new Event('1'));
        ed.dispatchEvent(new Event('2'))
    }

}
}

inner-peace avatar May 28 '15 12:05 inner-peace