-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
MockControlValueAccessor: auto spy writeValue
if a mock function was registered
#246
Comments
Hi @GerkinDev, might you share the template's code, or a small project on codesandbox.io? Simply fork it. Please correct me if I'm wrong. You have a component with control value accessor that is rendered under some circumstances and there's no direct access to it before the circumstances. Currently I think you can use describe('test', () => {
// spy we want to track
const writeValue = jasmine.createSpy('writeValue');
// injecting the spy into the desired component
beforeAll(() => MockInstance(MyValueAccessorComponent, instance => {
instance.writeValue = writeValue;
}));
// removing custom initialization from beforeAll
afterAll(MockReset);
beforeEach(() => MockBuilder(Component, Module));
it('test', () => {
const fixture = MockRender(Component);
// default - not rendered
expect(writeValue).not.toHaveBeenCalled();
// creating circumstances
fixture.point.componentInstance.condition = true;
fixture.detectChanges();
expect(writeValue).toHaveBeenCalledWith('foo');
});
}); |
Wow, GG, sorry, it actually does exactly what I want. And I've (mostly) RTFM. I just missed this part, which is pretty far in the README. So I guess I'd just call myself silly lazy bastard, and say that I think it should be easier to find. Such a big README is not that easy to know where to look for what. |
Anyway, for reference, RTFM: https://github.com/ike18t/ng-mocks#mockinstance |
Yeah, agree, that's where I struggle too. Too many things to describe in documentation. Might you describe how you read the documentation first time? |
Well, I'm gonna be totally honest with you: seeing the size of the readme, I read mostly code samples, headings, links and what is put on emphasis. There's just too much text to keep the full attention on the whole README. So I didn't really read pretty much everything else. I would have expected to see something talking about it in the How to create a mock component section, since a form control is most of the times a component, even though a directive can also be one. And because I didn't found what I was looking for, I did a plain I would have expected to have the following:
TL;DRThere is REALLY too much text and too few cross-references between sections, or examples on more precise cases. But adding examples would again increase the README size, and that is, IMHO, not an option. I guess the wiki, with a clear table of content easily reachable from the side, would be a pretty decent solution without having to build a complete docs site (even if there is already one, but it is, unfortunately, mostly useless in its current form IMHO 😞) |
Hi @GerkinDev, I totally agree with your feedback and thank you for being honest. Unfortunately, the biggest problem is available time for the project, that's why website has only simple examples and all docs are in the readme. It will be a wiki one day, the only question is when :) The current intention was to attract people:
But users have own ways 😄 Anyway, back to the business. And I would appreciate your feedback on the next 2 questions:
Thank you in advance! |
Hi @GerkinDev, might you check the comment above? |
Hi, Changes are OK IMO :) and yes, I've seen the collapsibles that greatly reduce the size of the readme; great compromise I think, and easy enough to spot. But maybe using headings in the collapsible summaries would make them easier to spot (and list in a TOC). Great job <3 |
HI @GerkinDev, thanks for the feedback, I'll try to implement it in near future. |
fix(#246): auto spy covers control value accessor too
v11.2.3 has been released and contains a fix for the issue. Feel free to reopen the issue or to submit a new one if you meet any problems. |
…monorepo chore(e2e/a9): update dependency zone.js to v0.10.3
Hi @GerkinDev, I hope this finds you well and healthy! I've created a separate website for documentation, might you check if it fits your expectations? |
Hi,
In the context of one of my tests, I have an input that is displayed only if a value is set on my host component, and bound with this value. That means I can't retrieve the input with
find
or other methods before defining the actual value, and thus, I can't spy on itswriteValue
method.By looking around in the code of ng-mocks, I saw that the jest and jasmine registers function for auto-mocking. Would it be possible to use this auto-mocking function instead of the stub function of
writeValue
? And would it be pertinent to use auto-mock functions on other methods of theControlValueAccessor
interface ?I'd be happy to PR. Kind of blocking me in my sprint, so I guess I'll have to fork anyway or skip this test altogether.
🍻 cheers !
The text was updated successfully, but these errors were encountered: