jubianchi / atoum.js

The modern, simple and intuitive PHP 5.3+ unit testing framework, now for JS
http://jubianchi.fr/atoum.js
16 stars 3 forks source link

Allow to reset a callback controller #5

Open marmotz opened 11 years ago

marmotz commented 11 years ago

I can't write this code:

        this
            .given(o = new MyObject())
            .and(o.setSomething(myCallback = this.generateCallback()))

            .if(o.doSomething())
                .callback(myCallback)
                    .wasCalled()

            .if(o.doOtherThing())
                .callback(myCallback)
                    .wasNotCalled()

Because, in the second test, the callback was already called in first test.

So, we need a way to reset the callback controller.

jubianchi commented 11 years ago

@marmotz you are totally right!

What about somethign like that:

var o, myCallback;

this
    .given(o = new MyObject())
    .and(o.setSomething(myCallback = this.generateCallback()))

    .if(o.doSomething())
        .callback(myCallback) .wasCalled()

    .resetCallback(myCallback)

    //...
;

I'll also add the same method for mocks and stubs (resetMock and resetStub)

marmotz commented 11 years ago

it seems great !