-
Notifications
You must be signed in to change notification settings - Fork 40
Add tests #37
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
Add tests #37
Conversation
|
This looks awesome. :) |
|
Still have much to do and learn. Will slowly add the the other commits. |
|
My sleep has messed up so I haven't had the time or energy to work on this but I'll get to it within the next week hopefully. Thanks for the patience :) |
|
How does one correctly mock away
My (TS) test code looks like: beforeEach(() => {
fetchMock.resetMocks();
let mock = jest.fn();
OMDbInstance = new OMDbAPI(new mock());
})
test("searchByTitle behavior when given garbage data", async () => {
fetchMock.mockResponseOnce(JSON.stringify({
data: "string"
}))
await expect(async () => await OMDbInstance.searchByTitle("sample")).rejects.toThrow();
expect(fetchMock).toHaveBeenCalledTimes(1);
});and I'm getting |
|
I will take a look at it when I have time. I am currently busy for the next few days. |
|
@AB1908 |
|
Absolutely fine! I'm supposed to be the one contributing haha and I'm asking for help, which is hilarious. I did post on Discord but didn't get a response so I'll continue experimenting. This is one of those times where I feel like I've hit a brick wall and I need help from someone with more jest knowledge. Hope you get a fixed laptop soon! |
|
I was just looking through the docs and maybe this can help you. |
|
I've been trying to figure out how that works. I guess I'll need some more time. I'm working on a fix to the SRS plugin as well. Maybe I'll try tackling some easier tests just so I can continue making progress. |
- Mocks need rewriting as they are not being created from module. Not scalable.
|
I added a very lazy mock since I couldn't mock modules correctly. The obvious improvement is to do something like: let pluginMock: MediaDbPlugin = jest.createMockFromModule("../main.ts");but this seems to fail with (not exact error message but similar) One thing I'm confused about is that since |
|
Hi again, it's been a while and progress has stalled but I've run into a few questions regarding the nature of the test suite. At the moment, I'm still focused on writing tests for the various APIs but I can't say they're quite necessary. The methods are mostly doing a bit of mapping and are private as well so do you think they are worth testing? Should we test a public method instead where the underlying implementation is in use but we don't necessarily care about its input? On a separate note, I feel that there's way too much duplication in the API wrappers and I'm considering refactoring it but I want to complete the test suite before embarking on that. I think the hand written mocks still work for now so if you think we should continue with this, I'll write the rest of them out. I've spent a decent amount of time trying to do mocks the correct way but I run into import resolution issues, instantiation issues or I just plainly don't understand what's happening at all. |
If you're talking about the API in
You're right, it will help having some tests before embarking on a refactoring. Those hand written mocks will also serve as a documentation about what we expect from the APIs. When I fixed the issue with Steam's API, I wasn't sure if there was a typo in the code or if it was the API that changed. If you still have issues with import resolution, instantiation and so one don't hesitate to ask me, I might be able to help. Note: even if you don't write all tests for all APIs, it will be very valuable. It will make it easier for the author or any contributors to add tests as you'll have done the heavy lifting of setting every things up. |
|
Thank you for the feedback and offer of help! I'm currently stuck rewriting a separate plugin but I'll get back on this soon! |
|
I've finally got a generic-ish test suite up and running. Will slowly add in phases. |
|
Hmm just learnt that we should be using |
|
I've made more progress and will add some commits over the next couple of days. Here are results: |
- Allows using JSON as objects - Allows jest to resolve node_modules
|
Many many thanks to @Fevol for handing me a Based on their guidance, I was also wondering if we should add a set of integration tests where we use real data. My chief concern was around jikan as there appears to be potential for deprecation but I don't see any immediate need. With API tests added, what are the next set of components we should focus on? Final output: |
|
One area I see for improvement are some of the MAL and OMDb tests as they could return several types of media. I'll think about this in the coming weeks. |
|
Thanks a lot. From quickly looking over it i am only confused by the ~7k changes in |
I hope I did this correctly. I have another file for testing utils and I'll push it after cleaning up. There's definitely lots of scope for improvement here. I also didn't include the package json and other config stuff since I'm not sure about the correct way to add those. We can commit those at the end I guess.