Repository: streamich/react-use
Pull request #787 (2019-11-20 22:53:45)

fix: TSX specs were ignored from `yarn test`
# Description

TSX specs were ignored from `yarn test`


## Type of change

<!-- Check all relevant options. -->
- [x] Bug fix _(non-breaking change which fixes an issue)_
- [ ] New feature _(non-breaking change which adds functionality)_
- [ ] **Breaking change** _(fix or feature that would cause existing functionality to not work as before)_

# Checklist
- [x] Read the [Contributing Guide](https://github.com/streamich/react-use/blob/master/CONTRIBUTING.md)
- [x] Perform a code self-review
- [x] Comment the code, particularly in hard-to-understand areas
- [x] Add documentation
- [x] Add hook's story at Storybook
- [x] Cover changes with tests
- [x] Ensure the test suite passes (`yarn test`)
- [x] Provide 100% tests coverage
- [x] Make sure code lints (`yarn lint`). Fix it with `yarn lint:fix` in case of failure.
- [x] Make sure types are fine (`yarn lint:types`).

<!-- If you can't check all the checkboxes right now - check what you can, create a Draft PR, make some changes if needed and get back to it when you will be able to put some marks in list. -->



Patch:
diff --git a/package.json b/package.json
index f1f18622..8cddbb08 100644
--- a/package.json
+++ b/package.json
@@ -154,7 +154,7 @@
     "clearMocks": true,
     "coverageDirectory": "coverage",
     "testMatch": [
-      "<rootDir>/tests/**/*.test.ts"
+      "<rootDir>/tests/**/*.test.(ts|tsx)"
     ]
   }
 }


Test patch:
diff --git a/tests/useAsyncFn.test.tsx b/tests/useAsyncFn.test.tsx
index d6643b72..2b2aa74a 100644
--- a/tests/useAsyncFn.test.tsx
+++ b/tests/useAsyncFn.test.tsx
@@ -8,7 +8,7 @@
 import { act, renderHook } from '@testing-library/react-hooks';
 import useAsyncFn, { AsyncState } from '../src/useAsyncFn';
 
-type AdderFn = (a: number, b: number) => Promise<number>;
+type AdderFn = (a?: number, b?: number) => Promise<number>;
 
 describe('useAsyncFn', () => {
   it('should be defined', () => {
@@ -17,8 +17,8 @@ describe('useAsyncFn', () => {
 
   describe('the callback can be awaited and return the value', () => {
     let hook;
-    const adder = async (a: number, b: number): Promise<number> => {
-      return a + b;
+    const adder: AdderFn = async (a?: number, b?: number): Promise<number> => {
+      return (a || 0) + (b || 0);
     };
 
     beforeEach(() => {
@@ -50,9 +50,9 @@ describe('useAsyncFn', () => {
   describe('args can be passed to the function', () => {
     let hook;
     let callCount = 0;
-    const adder = async (a: number, b: number): Promise<number> => {
+    const adder = async (a?: number, b?: number): Promise<number> => {
       callCount++;
-      return a + b;
+      return (a || 0) + (b || 0);
     };
 
     beforeEach(() => {
diff --git a/tests/useEnsuredForwardedRef.test.tsx b/tests/useEnsuredForwardedRef.test.tsx
index 7a6f4d17..fd7ed425 100644
--- a/tests/useEnsuredForwardedRef.test.tsx
+++ b/tests/useEnsuredForwardedRef.test.tsx
@@ -13,7 +13,7 @@ beforeEach(() => {
 
 afterEach(() => {
   document.body.removeChild(container);
-  container = null;
+  container = null!;
 });
 
 test('should return a valid ref with existing forwardedRef', () => {
@@ -38,7 +38,7 @@ test('should return a valid ref with existing forwardedRef', () => {
 
 test('should return a valid ref when the forwarded ref is undefined', () => {
   const { result } = renderHook(() => {
-    const ref = useEnsuredForwardedRef<HTMLDivElement>(undefined);
+    const ref = useEnsuredForwardedRef<HTMLDivElement>(undefined!);
 
     TestUtils.act(() => {
       ReactDOM.render(<div id="test_id" ref={ref} />, container);
diff --git a/tests/useIntersection.test.tsx b/tests/useIntersection.test.tsx
index decf2fed..fb83108b 100644
--- a/tests/useIntersection.test.tsx
+++ b/tests/useIntersection.test.tsx
@@ -102,7 +102,7 @@ describe('useIntersection', () => {
       ReactDOM.render(<div ref={targetRef} />, container);
     });
 
-    const initialObserverOptions = { root: null, threshold: 0.8 };
+    const initialObserverOptions = { root: null as HTMLElement | null, threshold: 0.8 };
     const { rerender } = renderHook(({ ref, options }) => useIntersection(ref, options), {
       initialProps: { ref: targetRef, options: initialObserverOptions },
     });
diff --git a/tests/usePreviousDistinct.test.tsx b/tests/usePreviousDistinct.test.tsx
index 1a24d7b4..67931bb3 100644
--- a/tests/usePreviousDistinct.test.tsx
+++ b/tests/usePreviousDistinct.test.tsx
@@ -1,5 +1,5 @@
 import { renderHook } from '@testing-library/react-hooks';
-import usePreviousDistinct, { Predicate } from '../usePreviousDistinct';
+import usePreviousDistinct, { Predicate } from '../src/usePreviousDistinct';
 
 describe('usePreviousDistinct', () => {
   it('should be defined', () => {
diff --git a/tests/useWindowSize.test.tsx b/tests/useWindowSize.test.tsx
index ebb4d8d7..ed75989f 100644
--- a/tests/useWindowSize.test.tsx
+++ b/tests/useWindowSize.test.tsx
@@ -1,7 +1,7 @@
 import { act, renderHook } from '@testing-library/react-hooks';
 import { replaceRaf } from 'raf-stub';
-import useWindowSize from '../useWindowSize';
-import { isClient } from '../util';
+import useWindowSize from '../src/useWindowSize';
+import { isClient } from '../src/util';
 
 declare var requestAnimationFrame: {
   reset: () => void;