How to verifyZeroInteractions on a mock with ts-mockito - ts-mockito

I am searching for an analogous to verifyZeroInteractions(mockObject) or verifyNoMoreInteractions(mockObject) with ts-mockito, but with no success so far. Is there a functionality to validate that no calls on any method have been done on a mock?
Thanks,

Related

Does Django RestFramework supports async views and class?

It will be helpful if someone helps me with a clear cut answer. If Yes any suggestion how to approach... coz, I try to use async with DRF but I am always ending with
"AssertionError: Expected a Response, HttpResponse or HttpStreamingResponse to be returned from the view, but received a <class 'coroutine'>" this error
Short answer: no.
(as for 02.12.2021, djangorestframework==3.12.4)
asnyc is not mentioned once in DRF docs.
Documentation search async No results found
Django does "support" async so DRF should too but all DRF features were programmed with non-async in mind and are not ready to work with async. By making your DRF code async you won't be able to use all DRF features flawlessly.
Just use fastapi, you will thank me later

Does Jest have a way to conditionally return a value based on input?

I'm used to do mocking (actually, faking, but, whatever) with Sinon.js by using withArgs extensively to conditionally return the fake value. And now I'm trying to migrate to Jest and I'm can't find anything similar in the mock API.
What I want:
const t = sinon.stub();
t.withArgs('foo').returns('bar');
console.log(t('foo')); // 'bar'
console.log(t('qux')); // undefined
It seems that the only way to do that in Jest is by using mockImplementation, which means that I must write the arg matcher by hand.
Is there a better way of doing this in Jest?
So far, there isn't any Jest builtin method.
There is an issue opened here and a feature proposal here.
Based on this question, there is a third party library that does something similar: https://github.com/timkindberg/jest-when

Does verifying the mock is need in minitest

I'm reading the mocking capability of minitest.
require "minitest/autorun"
mock = MiniTest::Mock.new
mock.expect(:use_any_string, true, [String])
mock.use_any_string("foo")
## mock.use_any_string(1)
## MockExpectationError: mocked method :use_any_string called with unexpected arguments [1]
## I do not understand the purpose for this
mock.verify
So I do not understand the purpose of using mock.verify since the trying to pass any another type(to use_any_string) other than String result in mock expectation error.
So why should one use assert mock.verify then?
You are right, you cannot set anything else to the configured mock, but if your mock is not called at all, then you can find out with mock.verify. So if your method under test should call the mocked method, you should verify that it was called at all.
You are correct, mock.expect(:use_any_string, true, [String]) will cause the test to fail if the expected call is not made on the mock.
However using mock.verify depends on how you compose your test. In your example you are explicitly calling the method you are testing with mock.use_any_string("foo") so there is no need to also call mock.verify.
You could get into a scenario where you are not making this call explicitly, or are expecting the mock to have had calls made at a certain time. These scenarios would take advantage of mock.verify calls.
(Another note, minitest has recently introduced assert_mock which can be used instead of mock.verify)

How can I test authlogic's current_user in Cucumber?

I am trying to use authlogic's test helpers in Cucumber, calling activate_authlogic.
Our application_controller has a current_user_session method.
When we drop into the debugger mid-story, controller returns a Authlogic::TestCase::MockController.
But when we call controller.current_user_session.
The error occurred while evaluating nil.current_user_session.
How does this mock suddenly become a nil?
And does this mock controller know about our application controllers' code?
I don't know authlogic (and if this answer is helpful at all), but where does that mock object come from in the first place? You shouldn't be using any mocks in you cucumber stories. Cucumber is like an integration test, testing the complete Rails Stack.
I use it, to make sure, that my view, controller and model specs haven't diverged from each other.

Is verify called automatically on Groovy's MockFor

According to the javadocs, Groovy's MockFor object always ends with a verify. Its StubFor docs say calling verify is up to the user. I read that as saying that verify will automatically be called on the MockFor object. However, in looking at the groovy samples that use MockFor on a Java object (http://svn.codehaus.org/groovy/trunk/groovy/groovy-core/src/test/groovy/mock/interceptor/MockForJavaTest.groovy), they call verify explicitly. I've found in my tests that I need to do the same. Are the docs just incorrect or maybe I'm misunderstanding. Any help would be appreciated.
thanks,
Jeff
According to the docs (http://groovy.codehaus.org/Groovy+Mocks), the instance-style mocking that's invoked with the proxyInstance() method (for Groovy) or the proxyDelegateInstance() method (for Java, as in the example you referenced) does indeed require an explicit call to verify.
It's the class-style mocking -- which is invoked by passing in a closure to the .use method -- that does an implicit verify. That's the case for both Mock and Stub.
My understanding of the difference between a Mock and a Stub is that it's a matter of what gets verified when verify is called, not how it's called. A mock validates that events happen in a certain order while a stub only cares that events happen a certain number of times.

Resources