-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
suggestion: Add some way to provide implementation #312
Comments
Hey @safareli, I documented why this is not implemented, and how you can work around it, in the FAQ. I'm curious to know your use cases. I usually find that I can change the design, or the tests, before needing to combine argument matchers with fakes. One can also use It.willCapture to verify arguments outside of an expectation. Your second example is interesting. If I understand it correctly, you mock the function and provide an implementation, and then set the argument expectations. It doesn't really work with the existing |
Both of my examples are trying to express same expectations but with different potential api. My use case is basically what's in example. I want to test that write is called and I also want data to be written to the WriteStream. it wouldn't be quite doable with existing strong-mock api. I've read the FAQ section but when using that approach we loose power of strong-mock with regards to asserting arguments shape. For example to solve this particular use case i'm falling back to jest like this:. const writeImplementation = () => {...}
const fs = {
write: jest.fn(writeImplementation)
}
declare const ws: WriteStream;
fs.write("a",ws);
fs.write("b",ws);
expect(fs.write.calls[0][0]).toEqual("a")
expect(fs.write.calls[1][0]).toEqual("b") |
But why? :) Does the code under test need to observe that the data was written? If so, you could do this: const out = It.willCapture<WriteStream>();
when(() => fs.write("a", out)).thenReturn();
fs.write("a", ws);
// This is the captured ws.
out?.value.write("...");
Correct, the workaround is not a full replacement for |
That could work for simple tests. But let's say you are building up more complicated environment for some function to test, it contains FS maybe some network services and then this function under test will invoke some things from those services. now question is when should we call |
When using strong-mock what i'm missing sometimes from jest is mockImplementation.
Would be great to be able to do something similar:
or
The text was updated successfully, but these errors were encountered: