Cheatography
https://cheatography.com
Tips for converting from Mocker to Sinon. Questions? Ask in #luna-server
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Stub/Spy Equivalents
t.mocker.installNewSpy(Foo, "bar")
|
const barSpy = t.sandbox.spy(Foo, "bar")
|
t.mocker.installNewMock(Foo, "bar")
|
const barStub = t.sandbox.stub(Foo, "bar")
|
|
Behavior Equivalents
|
|
If different behavior for different inputs (rare): |
.invoke(foo).andReturn(bar)
|
.withArgs(foo).returns(bar)
|
|
|
|
|
Stub a property (not a method) (runWithReplacedGlobals) |
|
|
Verification Equivalents (do you need it?)
|
|
|
No verification necessary! |
.on().invoke(arg1, arg2)
|
.alwaysCalledWithExactly(fooStub, arg1, arg2)
|
|
|
.expect().invoke(arg1, arg2)
|
.calledOnceWithExactly(fooStub, arg1, arg2)
|
|
|
|
Gives .on()
the behavior of .expect()
|
|
Matcher Equivalents
Matcher.hasKeyValues({ foo: bar })
|
Sinon.match({ foo: bar })
|
Necessary for most StateObjects (may surface as "Maximum call stack size exceeded"): |
Matcher.hasKeyValues({ task: expected_task })
|
Sinon.match({ task: Sinon.match.same(expected_task) })
|
You can also consider matching on e.g. task.global_id |
Matcher.hasExactKeyValues({ foo: bar })
|
|
|
|
|
|
Matcher.hasSubstring("foo")
|
|
Matcher.isInstanceOf(Foo)
|
Sinon.match.instanceOf(Foo)
|
Matcher.matchesRegex(/foo/)
|
|
|
|
Matcher.isEqual(foo, bar)
|
Sinon.match.same(foo, bar)
|
|
|
|
|
|