Fix tests for `hooks`

This commit is contained in:
Jonathan Edenström 2021-10-15 22:36:48 +02:00
parent e9d82745ce
commit 83e837955c
16 changed files with 68 additions and 67 deletions

View File

@ -10,6 +10,10 @@
"**/*.spec.tsx", "**/*.spec.tsx",
"**/*.spec.js", "**/*.spec.js",
"**/*.spec.jsx", "**/*.spec.jsx",
"**/*.test.ts",
"**/*.test.tsx",
"**/*.test.js",
"**/*.test.jsx",
"**/*.d.ts" "**/*.d.ts"
] ]
} }

View File

@ -0,0 +1,12 @@
{
"presets": [
[
"@nrwl/react/babel",
{
"runtime": "automatic",
"useBuiltIns": "usage"
}
]
],
"plugins": []
}

View File

@ -1,15 +0,0 @@
module.exports = function(api) {
api.cache(true);
const presets = [
'@nrwl/next/babel',
'module:metro-react-native-babel-preset'
];
const plugins = [
["@babel/plugin-proposal-private-property-in-object", { "loose": false }]
];
return {
presets,
plugins
};
};

View File

@ -1,19 +1,19 @@
import { Api } from './api' import { Api } from './api'
import { FetcherOptions } from './fetcher'
import { Fetch } from './types'
import { import {
RNCookieManager, RNCookieManager,
ToughCookieJar, ToughCookieJar,
wrapReactNativeCookieManager, wrapReactNativeCookieManager,
wrapToughCookie, wrapToughCookie,
} from './cookies' } from './cookies'
import { FetcherOptions } from './fetcher'
import { Fetch } from './types'
export { Api, FetcherOptions }
export * from './types'
export { LoginStatusChecker } from './loginStatus' export { LoginStatusChecker } from './loginStatus'
export * from './types'
export { Api, FetcherOptions }
const init = ( const init = (
fetch: Fetch, fetchImpl: Fetch,
cookieManagerImpl: RNCookieManager | ToughCookieJar, cookieManagerImpl: RNCookieManager | ToughCookieJar,
options?: FetcherOptions options?: FetcherOptions
): Api => { ): Api => {
@ -21,7 +21,7 @@ const init = (
const cookieManager = ((cookieManagerImpl as RNCookieManager).get) const cookieManager = ((cookieManagerImpl as RNCookieManager).get)
? wrapReactNativeCookieManager(cookieManagerImpl as RNCookieManager) ? wrapReactNativeCookieManager(cookieManagerImpl as RNCookieManager)
: wrapToughCookie(cookieManagerImpl as ToughCookieJar) : wrapToughCookie(cookieManagerImpl as ToughCookieJar)
return new Api(fetch, cookieManager, options) return new Api(fetchImpl, cookieManager, options)
} }
export default init export default init

View File

@ -10,6 +10,10 @@
"**/*.spec.tsx", "**/*.spec.tsx",
"**/*.spec.js", "**/*.spec.js",
"**/*.spec.jsx", "**/*.spec.jsx",
"**/*.test.ts",
"**/*.test.tsx",
"**/*.test.js",
"**/*.test.jsx",
"**/*.d.ts" "**/*.d.ts"
] ]
} }

View File

@ -10,6 +10,10 @@
"**/*.spec.tsx", "**/*.spec.tsx",
"**/*.spec.js", "**/*.spec.js",
"**/*.spec.jsx", "**/*.spec.jsx",
"**/*.test.ts",
"**/*.test.tsx",
"**/*.test.js",
"**/*.test.jsx",
"**/*.d.ts" "**/*.d.ts"
] ]
} }

12
libs/hooks/.babelrc Normal file
View File

@ -0,0 +1,12 @@
{
"presets": [
[
"@nrwl/react/babel",
{
"runtime": "automatic",
"useBuiltIns": "usage"
}
]
],
"plugins": []
}

View File

@ -1,30 +0,0 @@
module.exports = function(api) {
api.cache(true);
const presets = [
[
'@nrwl/next/babel',
{
modules: 'auto',
targets: {
browsers: ['defaults']
},
}
],
"@nrwl/react/babel",
];
const plugins = [
'@babel/plugin-transform-runtime',
'@babel/plugin-proposal-class-properties',
["@babel/plugin-proposal-private-property-in-object", { "loose": false }],
"@babel/plugin-transform-runtime",
{
"regenerator": true,
"corejs": 3
}
];
return {
presets,
plugins
};
};

View File

@ -6,7 +6,4 @@ module.exports = {
}, },
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/libs/hooks', coverageDirectory: '../../coverage/libs/hooks',
testEnvironment: 'jsdom',
clearMocks: true,
setupFilesAfterEnv: ['<rootDir>/jest.setup.js']
} }

View File

@ -1 +0,0 @@
import 'regenerator-runtime/runtime'

View File

@ -19,5 +19,8 @@
}, },
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
},
"devDependencies": {
"jest": "*"
} }
} }

View File

@ -18,12 +18,12 @@ const { default: init } = jest.requireActual(
'@skolplattformen/api-skolplattformen' '@skolplattformen/api-skolplattformen'
) )
const wait = (ms) => new Promise((res) => setTimeout(res, ms)) const wait = (ms: number) => new Promise((res) => setTimeout(res, ms))
describe('hooks with fake data', () => { describe('hooks with fake data', () => {
let api let api: any
let storage let storage: any
const wrapper = ({ children }) => ( const wrapper = ({ children }: { children: React.ReactNode }) => (
<ApiProvider api={api} storage={storage}> <ApiProvider api={api} storage={storage}>
{children} {children}
</ApiProvider> </ApiProvider>
@ -92,7 +92,7 @@ describe('hooks with fake data', () => {
}) })
}) })
describe('data belonging to one child', () => { describe('data belonging to one child', () => {
let child let child: any
beforeEach(async () => { beforeEach(async () => {
;[child] = await api.getChildren() ;[child] = await api.getChildren()
}) })
@ -178,7 +178,7 @@ describe('hooks with fake data', () => {
}) })
it('handles reloads', async () => { it('handles reloads', async () => {
await act(async () => { await act(async () => {
store.dispatch({ type: 'CLEAR' }) store.dispatch({ type: 'CLEAR' } as any) // fixes test for invalid type
const [child] = await api.getChildren() const [child] = await api.getChildren()

View File

@ -10,6 +10,10 @@
"**/*.spec.tsx", "**/*.spec.tsx",
"**/*.spec.js", "**/*.spec.js",
"**/*.spec.jsx", "**/*.spec.jsx",
"**/*.test.ts",
"**/*.test.tsx",
"**/*.test.js",
"**/*.test.jsx",
"**/*.d.ts" "**/*.d.ts"
] ]
} }

View File

@ -96,7 +96,7 @@
"@types/detox": "17.14.2", "@types/detox": "17.14.2",
"@types/he": "^1.1.1", "@types/he": "^1.1.1",
"@types/i18n-js": "^3.8.2", "@types/i18n-js": "^3.8.2",
"@types/jest": "26.0.24", "@types/jest": "^27.0.2",
"@types/luxon": "^1.26.4", "@types/luxon": "^1.26.4",
"@types/node": "14.14.33", "@types/node": "14.14.33",
"@types/node-fetch": "^2.5.10", "@types/node-fetch": "^2.5.10",

View File

@ -20,6 +20,5 @@
"@skolplattformen/curriculum": ["libs/curriculum/src/index.ts"], "@skolplattformen/curriculum": ["libs/curriculum/src/index.ts"],
"@skolplattformen/hooks": ["libs/hooks/src/index.ts"] "@skolplattformen/hooks": ["libs/hooks/src/index.ts"]
} }
}, }
"exclude": ["node_modules", "tmp"]
} }

View File

@ -2535,7 +2535,7 @@
dependencies: dependencies:
"@types/istanbul-lib-report" "*" "@types/istanbul-lib-report" "*"
"@types/jest@*", "@types/jest@26.0.24": "@types/jest@*":
version "26.0.24" version "26.0.24"
resolved "https://registry.npmjs.org/@types/jest/-/jest-26.0.24.tgz" resolved "https://registry.npmjs.org/@types/jest/-/jest-26.0.24.tgz"
integrity sha512-E/X5Vib8BWqZNRlDxj9vYXhsDwPYbPINqKF9BsnSoon4RQ0D9moEuLD8txgyypFLH7J4+Lho9Nr/c8H0Fi+17w== integrity sha512-E/X5Vib8BWqZNRlDxj9vYXhsDwPYbPINqKF9BsnSoon4RQ0D9moEuLD8txgyypFLH7J4+Lho9Nr/c8H0Fi+17w==
@ -2543,6 +2543,14 @@
jest-diff "^26.0.0" jest-diff "^26.0.0"
pretty-format "^26.0.0" pretty-format "^26.0.0"
"@types/jest@^27.0.2":
version "27.0.2"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-27.0.2.tgz#ac383c4d4aaddd29bbf2b916d8d105c304a5fcd7"
integrity sha512-4dRxkS/AFX0c5XW6IPMNOydLn2tEhNhJV7DnYK+0bjoJZ+QTmfucBlihX7aoEsh/ocYtkLC73UbnBXBXIxsULA==
dependencies:
jest-diff "^27.0.0"
pretty-format "^27.0.0"
"@types/json-schema@^7.0.4", "@types/json-schema@^7.0.5", "@types/json-schema@^7.0.7", "@types/json-schema@^7.0.8": "@types/json-schema@^7.0.4", "@types/json-schema@^7.0.5", "@types/json-schema@^7.0.7", "@types/json-schema@^7.0.8":
version "7.0.9" version "7.0.9"
resolved "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz" resolved "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz"
@ -8189,7 +8197,7 @@ jest-diff@^26.0.0:
jest-get-type "^26.3.0" jest-get-type "^26.3.0"
pretty-format "^26.6.2" pretty-format "^26.6.2"
jest-diff@^27.2.5: jest-diff@^27.0.0, jest-diff@^27.2.5:
version "27.2.5" version "27.2.5"
resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-27.2.5.tgz#908f7a6aca5653824516ad30e0a9fd9767e53623" resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-27.2.5.tgz#908f7a6aca5653824516ad30e0a9fd9767e53623"
integrity sha512-7gfwwyYkeslOOVQY4tVq5TaQa92mWfC9COsVYMNVYyJTOYAqbIkoD3twi5A+h+tAPtAelRxkqY6/xu+jwTr0dA== integrity sha512-7gfwwyYkeslOOVQY4tVq5TaQa92mWfC9COsVYMNVYyJTOYAqbIkoD3twi5A+h+tAPtAelRxkqY6/xu+jwTr0dA==
@ -11368,7 +11376,7 @@ pretty-format@^26.0.0, pretty-format@^26.0.1, pretty-format@^26.5.2, pretty-form
ansi-styles "^4.0.0" ansi-styles "^4.0.0"
react-is "^17.0.1" react-is "^17.0.1"
pretty-format@^27.2.2, pretty-format@^27.2.5: pretty-format@^27.0.0, pretty-format@^27.2.2, pretty-format@^27.2.5:
version "27.2.5" version "27.2.5"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-27.2.5.tgz#7cfe2a8e8f01a5b5b29296a0b70f4140df0830c5" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-27.2.5.tgz#7cfe2a8e8f01a5b5b29296a0b70f4140df0830c5"
integrity sha512-+nYn2z9GgicO9JiqmY25Xtq8SYfZ/5VCpEU3pppHHNAhd1y+ZXxmNPd1evmNcAd6Hz4iBV2kf0UpGth5A/VJ7g== integrity sha512-+nYn2z9GgicO9JiqmY25Xtq8SYfZ/5VCpEU3pppHHNAhd1y+ZXxmNPd1evmNcAd6Hz4iBV2kf0UpGth5A/VJ7g==