Hi,
If anyone is interested in applying TDD and Unit testing in general, let me know your thoughts about the repo in https://github.com/ihassin/fitbit-coachusa, that shows how to do so locally (using your favourite IDE) and then uploading the code to Fitbit Studio; all this in the hope that one day Fitbit will support a CLI to upload projects and releve us from the UI.
Comments welcome, fork it and make it better!
Thanks,
Itamar
@ihassin: I'll give it a closer look, thanks for sharing. In the meantime, can you add your project in our OSS repository please?
Best AnswerThank you Fred, I shall add it to that repo under "examples" as showing the bus times is not a true app, but just an example of how to get Jest working with the code.
I am looking forward to your and others' comments about my code as I am not an expert in any of this, just wanted to hack my way in to getting tests running in both dev and Fitbit environments.
Best Answer
Best Answer
Fitbit Developers oversee the SDK and API forums. We're here to answer questions about Fitbit developer tools, assist with projects, and make sure your voice is heard by the development team.
With the release of our new CLI SDK tools, Jest integration is super simple. Pop the following in a jest.config.js:
module.exports = {
transform: {
".(t|j)sx?": "ts-jest",
},
moduleFileExtensions: [
"ts",
"tsx",
"js",
"jsx",
],
testRegex: ".*\\.test\\.(t|j)sx?$",
clearMocks: true,
restoreMocks: true,
testEnvironment: 'node',
};
And add "jest" and "ts-jest" to your devDependencies. "yarn test" should just work then and pick up .test.js files.
As for Fitbit APIs you want to mock out, use jest.mock('file-transfer') or similar, and then your actual application code can remain unmodified.