Skip to content

Expectation counts wrong the method calls #70

Description

@inner-peace

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'))
    }

}
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions