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

add basic test suites for hooks folder #476

Merged
merged 2 commits into from
May 11, 2022
Merged

Conversation

cescoferraro
Copy link
Contributor

This PR creates basic test suites for the hooks placed at the hooks folder

Changes

  • define typing for existing hooks
  • add tests

Checklist

  • tested locally
  • added new dependencies
  • updated the docs
  • added a test

Copy link
Collaborator

@xoscar xoscar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @cescoferraro I left some comments. Let me know what you think.

A separate question: Could we move the test files under a __tests__ folder inside of the same hooks one? Thanks!

web/package.json Outdated
@@ -39,7 +39,8 @@
"scripts": {
"start": "craco start",
"build": "craco build",
"test:unit": "craco test --watchAll=false",
"test:work": "craco test --watchAll=false --coverage ./src/hooks --collectCoverageFrom='src/hooks/**/*.(tsx|ts)'",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this leak into the commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad

web/package.json Outdated
@@ -78,7 +79,8 @@
"jest": {
"transformIgnorePatterns": [
"/node_modules/(?!antd|@ant-design|rc-.+?|@babel/runtime).+(js|jsx)$"
]
],
"testMatch": [ "<rootDir>/src/hooks/**/*.test.tsx" ]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this match everything not only hooks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad

export const useDAGChart = (
spanMap: TSpanMap = {}
): void | {
dag: Dag<{id: string; parentIds: string[]}, undefined>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we encapsulate this into an interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

useEffect(() => {
let interval: any = null;

console.log(1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess these logs aren't supposed to be here right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const payload = {callback, isPolling: true, delay: 0};
await renderHook(() => usePolling(payload));

expect(callback).toBeCalledTimes(0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the tests be more extensive to cover the different scenarios, like when the isPolling could change, etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am focusing on getting test suites present.
testing setInterval is a bit tricky.
I am aiming on getting coverage up on those 3 folders.

Copy link
Collaborator

@xoscar xoscar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! 🚀

@cescoferraro cescoferraro merged commit 1762e75 into main May 11, 2022
@mathnogueira mathnogueira deleted the feature/hooks_testing branch May 25, 2022 16:55
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

Successfully merging this pull request may close these issues.

2 participants