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

Refactor ResultList Spec #48

Open
LionOps opened this issue Feb 11, 2017 · 0 comments
Open

Refactor ResultList Spec #48

LionOps opened this issue Feb 11, 2017 · 0 comments

Comments

@LionOps
Copy link
Contributor

LionOps commented Feb 11, 2017

While result-list-spec is a good test file, it is wrongly mocking the underlying XHR responses via Mockagent rather than mocking the in-lib boundary [retrieve[(https://github.com/yola/pixabayjs/blob/6f8e22aa36209204f33bf2cfadb1b28d37e7c3bb/src/retrieve.js).

We should refactor the test to mock retrieve and introduce an integration test for retrieve that asserts the correct url is being created in combination with https://httpbin.org/

Note that sinon would not support mocking retrieve as is because we are exporting a function rather than an object. https://github.com/testdouble/testdouble.js (TD) supports mocking local imports, which would allow us to get around the problem of not being able to export functions and mock them in tests.

However, I gave a cursory attempt to refactor pixabay-spec using TD and ran into issues (which may be due to my inexperience with the lib).

How to refactor this? TD doesn't allow partial mocks, and the point of the test is to assert that the correct url is being used. Is the test itself flawed in design? Maybe it would be better to assert that the ResultList's properties (which are private) have the correct url. Maybe the test shouldn't exist at all. I tried mocking the client except for the function under test as well as mocking the ResultList constructor. The latter seems like a dead end due to testdouble/testdouble.js#54.

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

1 participant