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

Convert to TypeScript #520

Merged
merged 56 commits into from Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
b7c28dc
Added tsconfig.json. Modified eslint config
nobrayner Dec 8, 2020
a7b9412
Convert src/cleanup.js to TypeScript
nobrayner Dec 9, 2020
cdfca10
Change src/cleanup.ts to use inline types
nobrayner Dec 9, 2020
5e5a248
revert eslintrc
merodiro Dec 9, 2020
07278d0
disable eslint for cleanup import
merodiro Dec 9, 2020
e8b9dae
convert index to typescript
merodiro Dec 9, 2020
bc2a6c3
Worked on typing asyncUtils. Removed deprecated wait. Disabled import…
juhanakristian Dec 10, 2020
f58e7f0
Fix incorrect cleanup callback type
nobrayner Dec 10, 2020
a8ece29
asyncUtils has been updated. Two lines are disabled for eslint.
tigerabrodi Dec 10, 2020
7e45893
remove unnecessary eslint disable
merodiro Dec 10, 2020
b8ddea3
Prettier was stripping try catch types
JacobMGEvans Dec 11, 2020
4445273
Type for callback handle generic input & undefined handled by nullish…
JacobMGEvans Dec 11, 2020
05e9a38
comments for review
JacobMGEvans Dec 11, 2020
6879cfd
VoidFunction in place for void until decided behavior for waitFor()
JacobMGEvans Dec 11, 2020
8f902ea
Utilizing OR operator with generic Types allows for desired behavior …
JacobMGEvans Dec 11, 2020
2c2908b
mistakenly left out linter ignores in last commit
JacobMGEvans Dec 11, 2020
58b9b37
Minimum types started for Pure file
JacobMGEvans Dec 11, 2020
4818ced
removed comments -- answered in PR
JacobMGEvans Dec 11, 2020
4c8d1e2
Generic HTML types for initialProps
JacobMGEvans Dec 11, 2020
3f9d853
Generic HTML types for initialProps
JacobMGEvans Dec 11, 2020
d2dadf5
Generic type for callback and initialProps
JacobMGEvans Dec 11, 2020
1dba932
Generics added and CB toplevel same generic pattern added
JacobMGEvans Dec 11, 2020
6b19d1b
force rebuild with unbound method eslint ignore
JacobMGEvans Dec 12, 2020
9604dd7
parser issue -- attempt to fix by removing specific TS eslint rule
JacobMGEvans Dec 12, 2020
b84a0de
Newer versions of ESLint might resolve the parser issue
JacobMGEvans Dec 12, 2020
319cbba
Added configs to get started on test conversion
JacobMGEvans Dec 12, 2020
ec18c2a
Generic type for resultContainer
merodiro Dec 12, 2020
7c8ddee
convert tests that require no changes
merodiro Dec 12, 2020
e3ecb24
add types to cleanup test
merodiro Dec 12, 2020
d74e947
Test TS Overhaul
JacobMGEvans Dec 12, 2020
d85fb85
Amr updated types useEffect
JacobMGEvans Dec 12, 2020
ce60735
Jens suggestion for more generic number key type
JacobMGEvans Dec 12, 2020
74793cd
Remove wait reference from docs
nobrayner Dec 12, 2020
acfed0d
Add nobrayner to contributors
nobrayner Dec 12, 2020
b77b17a
Add JacobMGEvans to contributors
nobrayner Dec 12, 2020
b5977f6
Update src/pure.tsx
JacobMGEvans Dec 13, 2020
e6997ca
Add tigerabrodi to contributors
nobrayner Dec 13, 2020
3485a02
Add Amr, Juhana, and Jens to contributors
nobrayner Dec 13, 2020
ed2bb4a
update suspenseHook, cache type and the type of the error in catch.
tigerabrodi Dec 13, 2020
65e4d0c
cleanup.ts, update the way addCleanup adds another callback to cleanu…
tigerabrodi Dec 13, 2020
d51ddc1
Made generics more descriptive, made TestHook generic
nobrayner Dec 14, 2020
fb93f4e
Remove some eslint disables that didn't do anything
nobrayner Dec 14, 2020
1779a85
Remove DefinitelyTyped reference in CONTRIBUTING.md
nobrayner Dec 14, 2020
78c146e
chore: disable declaration for tests
marcosvega91 Dec 14, 2020
9d957ba
Removes createTimeoutError. Adds constructor to TimeoutError. Adds ty…
juhanakristian Dec 14, 2020
d1c36bd
Remove conditional in TestHook for hookProps
mpeyper Dec 15, 2020
21a1c6e
Replace old types defs with referenced types in dependencies
mpeyper Dec 15, 2020
d621cda
Remove destructuring of `testRenderer`
mpeyper Dec 15, 2020
900e89c
Disabled floating promise lint rule globally
mpeyper Dec 15, 2020
4ead36f
Refactor TestHook catch to not disable lint rules
mpeyper Dec 15, 2020
25509ba
Disabled eslint error for while(true)
mpeyper Dec 15, 2020
db8a6f3
Cleaned up some line warnings from tests
mpeyper Dec 15, 2020
f0d080e
Added "typecheck" kcd-script to improve "validate" script
mpeyper Dec 15, 2020
84a40ad
Clean up ThrowError type in errorHook tests
mpeyper Dec 15, 2020
f33e457
Replace VoidFunction with () => void
mpeyper Dec 15, 2020
a5754f2
Replace CallableFunction with a more explicit function type
mpeyper Dec 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 58 additions & 0 deletions .all-contributorsrc
Expand Up @@ -212,6 +212,64 @@
"contributions": [
"code"
]
},
{
"login": "nobrayner",
"name": "Braydon Hall",
"avatar_url": "https://avatars2.githubusercontent.com/u/40751395?v=4",
"profile": "https://github.com/nobrayner",
"contributions": [
"code"
]
},
{
"login": "JacobMGEvans",
"name": "Jacob M-G Evans",
"avatar_url": "https://avatars1.githubusercontent.com/u/27247160?v=4",
"profile": "https://dev.to/jacobmgevans",
"contributions": [
"code",
"test"
]
},
{
"login": "tigerabrodi",
"name": "Tiger Abrodi",
"avatar_url": "https://avatars1.githubusercontent.com/u/49603590?v=4",
"profile": "https://tigerabrodi.dev/",
"contributions": [
"code",
"test"
]
},
{
"login": "merodiro",
"name": "Amr A.Mohammed",
"avatar_url": "https://avatars1.githubusercontent.com/u/17033502?v=4",
"profile": "https://github.com/merodiro",
"contributions": [
"code",
"test"
]
},
{
"login": "juhanakristian",
"name": "Juhana Jauhiainen",
"avatar_url": "https://avatars1.githubusercontent.com/u/544386?v=4",
"profile": "https://github.com/juhanakristian",
"contributions": [
"code"
]
},
{
"login": "jensmeindertsma",
"name": "Jens Meindertsma",
"avatar_url": "https://avatars3.githubusercontent.com/u/64677517?v=4",
"profile": "https://github.com/jensmeindertsma",
"contributions": [
"code",
"test"
]
}
],
"commitConvention": "none"
Expand Down
8 changes: 6 additions & 2 deletions .eslintrc
@@ -1,10 +1,14 @@
{
"extends": "./node_modules/kcd-scripts/eslint.js",
"extends": ["./node_modules/kcd-scripts/eslint.js"],
"rules": {
"max-lines-per-function": "off",
"no-constant-condition": "off",
"no-await-in-loop": "off",
"react-hooks/rules-of-hooks": "off",
"no-console": "off"
"no-console": "off",
"import/no-unresolved": "off"
},
"parserOptions": {
"project": ["./tsconfig.json", "./test/tsconfig.json"]
}
}
5 changes: 0 additions & 5 deletions CONTRIBUTING.md
Expand Up @@ -27,11 +27,6 @@ select the added contribution type.
Please make sure to run the tests before you commit your changes. You can do so by running
`npm test`.

### Update Typings

The TypeScript type definitions can be found in the
[DefinitelyTyped repo](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/testing-library__react-hooks).

## Help needed

Please check out the
Expand Down
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -192,6 +192,14 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center"><a href="https://github.com/joshuaellis"><img src="https://avatars0.githubusercontent.com/u/37798644?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Josh</b></sub></a><br /><a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=joshuaellis" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/Goldziher"><img src="https://avatars1.githubusercontent.com/u/30733348?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Na'aman Hirschfeld</b></sub></a><br /><a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=Goldziher" title="Code">💻</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/nobrayner"><img src="https://avatars2.githubusercontent.com/u/40751395?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Braydon Hall</b></sub></a><br /><a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=nobrayner" title="Code">💻</a></td>
<td align="center"><a href="https://dev.to/jacobmgevans"><img src="https://avatars1.githubusercontent.com/u/27247160?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jacob M-G Evans</b></sub></a><br /><a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=JacobMGEvans" title="Code">💻</a> <a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=JacobMGEvans" title="Tests">⚠️</a></td>
<td align="center"><a href="https://tigerabrodi.dev/"><img src="https://avatars1.githubusercontent.com/u/49603590?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tiger Abrodi</b></sub></a><br /><a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=tigerabrodi" title="Code">💻</a> <a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=tigerabrodi" title="Tests">⚠️</a></td>
<td align="center"><a href="https://github.com/merodiro"><img src="https://avatars1.githubusercontent.com/u/17033502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Amr A.Mohammed</b></sub></a><br /><a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=merodiro" title="Code">💻</a> <a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=merodiro" title="Tests">⚠️</a></td>
<td align="center"><a href="https://github.com/juhanakristian"><img src="https://avatars1.githubusercontent.com/u/544386?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Juhana Jauhiainen</b></sub></a><br /><a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=juhanakristian" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/jensmeindertsma"><img src="https://avatars3.githubusercontent.com/u/64677517?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jens Meindertsma</b></sub></a><br /><a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=jensmeindertsma" title="Code">💻</a> <a href="https://github.com/testing-library/react-hooks-testing-library/commits?author=jensmeindertsma" title="Tests">⚠️</a></td>
</tr>
</table>

<!-- markdownlint-restore -->
Expand Down
25 changes: 0 additions & 25 deletions docs/api-reference.md
Expand Up @@ -259,28 +259,3 @@ The maximum amount of time in milliseconds (ms) to wait. By default, no timeout
If this option is set to `true`, any errors that occur while waiting are treated as a failed check.
If this option is set to `false`, any errors that occur while waiting cause the promise to be
rejected. By default, errors are not suppressed for this utility.

### `wait`

_(DEPRECATED, use [`waitFor`](/reference/api#waitfor) instead)_

```js
function wait(callback: function(): boolean|void, options?: {
timeout?: number,
suppressErrors?: boolean
}): Promise<void>
```

Returns a `Promise` that resolves if the provided callback executes without exception and returns a
truthy or `undefined` value. It is safe to use the [`result` of `renderHook`](/reference/api#result)
in the callback to perform assertion or to test values.

#### `timeout`

The maximum amount of time in milliseconds (ms) to wait. By default, no timeout is applied.

#### `suppressErrors`

If this option is set to `true`, any errors that occur while waiting are treated as a failed check.
If this option is set to `false`, any errors that occur while waiting cause the promise to be
rejected. By default, errors are suppressed for this utility.
3 changes: 2 additions & 1 deletion jest.config.js
@@ -1,6 +1,7 @@
// eslint-disable-next-line
const { jest: jestConfig } = require('kcd-scripts/config')

module.exports = Object.assign(jestConfig, {
roots: ['<rootDir>/src', '<rootDir>/test'],
testMatch: ['<rootDir>/test/*.js']
testMatch: ['<rootDir>/test/*.(ts|tsx|js)']
})
8 changes: 6 additions & 2 deletions package.json
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.0-semantically-released",
"description": "Simple and complete React hooks testing utilities that encourage good testing practices.",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"keywords": [
"testing",
"react",
Expand Down Expand Up @@ -40,16 +41,19 @@
"@types/testing-library__react-hooks": "^3.4.0"
mpeyper marked this conversation as resolved.
Show resolved Hide resolved
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.9.1",
"@typescript-eslint/parser": "^4.9.1",
"all-contributors-cli": "6.19.0",
"codecov": "3.8.1",
"docz": "2.3.1",
"docz-theme-default": "1.2.0",
"docz-utils": "2.3.0",
"eslint": "7.15.0",
"kcd-scripts": "7.5.2",
"prettier": "^2.2.1",
"react": "17.0.1",
"react-test-renderer": "17.0.1",
"typescript": "4.1.2",
"eslint": "7.15.0"
"typescript": "4.1.2"
},
"peerDependencies": {
"react": ">=16.9.0",
Expand Down
123 changes: 0 additions & 123 deletions src/asyncUtils.js

This file was deleted.