You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suppose I have a test for a class that does things:
function ClassThatDoesThings(){}
ClassThatDoesThings.prototype.doThings = function() {...}
ClassThatDoesThings.prototype.doMoreThings = function() {...}
ClassThatDoesThings.prototype.doAllTheThings = function() {
this.doThings();
this.doMoreThings();
}
var thinger = new ClassThatDoesThings(),
mock = sinon.mock(thinger);
mock.expect('doThings').once();
mock.expect('doMoreThings').once();
thinger.doAllTheThings();
mock.verify();
The class then becomes too complex and I use composition to split it up. The original class is now sort of a mediator and I want to verify it forwards the calls correctly.
function ClassThatDoesBasicThings(){}
ClassThatDoesBasicThings.prototype.do = function() {...}
function ClassThatDoesMoreThings(){}
ClassThatDoesMoreThings.prototype.do = function() {...}
function ClassThatDoesThings( basic, more ) {
this.basic = basic;
this.more = more;
}
ClassThatDoesThings.prototype.doAllTheThings = function() {
this.basic.do();
this.more.do();
}
var basicThinger = new ClassThatDoesBasicThings(),
moreThinger = new ClassThatDoesMoreThings(),
basicMock = sinon.mock(basicThinger),
moreMock = sinon.mock(moreThinger),
thinger = new ClassThatDoesThings( basicThinger, moreThinger );
basicMock.expect('do').once();
moreMock.expect('do').once();
thinger.doAllTheThings();
mock.verify();
Suddenly the error messages thrown by mock.verify() are not so useful since both functions are called do(). There should be a way to supply a different name, maybe
basicMock.expect('do', 'basic.do').once();
or
basicMock.expect('do').named('basic.do').once();
(I understand that there is supposed to be only one mock per test; but that kind of goes against how mocks are normally used. It does not seem reasonable to force a completely different syntax on tests because of an internal refactoring that should have no visible effects.)
The text was updated successfully, but these errors were encountered:
Suppose I have a test for a class that does things:
The class then becomes too complex and I use composition to split it up. The original class is now sort of a mediator and I want to verify it forwards the calls correctly.
Suddenly the error messages thrown by
mock.verify()
are not so useful since both functions are calleddo()
. There should be a way to supply a different name, maybeor
(I understand that there is supposed to be only one mock per test; but that kind of goes against how mocks are normally used. It does not seem reasonable to force a completely different syntax on tests because of an internal refactoring that should have no visible effects.)
The text was updated successfully, but these errors were encountered: