Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having something like "verifyNoFurtherInvocations(mock)" would be nice (feature request) #176

Closed
pingvinen opened this issue Jan 3, 2017 · 2 comments

Comments

@pingvinen
Copy link

I often find it useful to be able to verify that no methods are called on a mocked class (in certain cases of course).

Consider the following case:

function MyClass() {}
MyClass.prototype.a = function() {};
MyClass.prototype.b = function() {};
function underTest(myClassInstance) {
	if (..something..) {
		return;
	}

	myClassInstance.a();
}
it('does nothing on MyClass if something', () => {
	// setup to trigger "something"-case

	underTest(mockedMyClass);

	td.verifyNoFurtherInvocations(mockedMyClass);
});

I could write a test that uses td.verify(..) with times:0 on each of the methods on MyClass, but that is not particularly semantic and it would also need to be updated whenever a new method was added to MyClass.

Disclaimer: I come from languages like C# and Java and I am new to nodejs, so it might be that I am simply doing something that makes no sense in this world.

@searls
Copy link
Member

searls commented Jan 3, 2017

This is excluded by design, but if really needed you can work around it as you suggested above with the times: 0 option. For a related discussion on why this is not encouraged by the API, see: #170 (comment)

@searls searls closed this as completed Jan 3, 2017
@pingvinen
Copy link
Author

I personally prefer tests to be explicit and semantic as that makes it easier to reason about them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants