Skip to content

Commit 525ed6e

Browse files
Adjusted tests to use new faker methods for generating mock data.
1 parent 63e047c commit 525ed6e

5 files changed

Lines changed: 179 additions & 113 deletions

File tree

.eslintrc.js

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,4 @@
1-
const path = require('path');
2-
31
module.exports = {
42
root: true,
5-
ignorePatterns: [
6-
'app.plugin.js',
7-
'.eslintrc.js',
8-
'cli.js',
9-
'react-native.config.js',
10-
'docs',
11-
'example',
12-
],
13-
14-
parser: '@typescript-eslint/parser',
15-
plugins: ['@typescript-eslint', 'react-hooks'],
16-
17-
extends: [
18-
'eslint:recommended',
19-
'plugin:@typescript-eslint/eslint-recommended',
20-
'plugin:@typescript-eslint/recommended',
21-
'plugin:@typescript-eslint/recommended-requiring-type-checking',
22-
],
23-
24-
parserOptions: {
25-
project: path.join(__dirname, 'tsconfig.json'),
26-
},
27-
28-
env: {
29-
es2022: true,
30-
},
31-
32-
rules: {
33-
'react-hooks/rules-of-hooks': 'error',
34-
'react-hooks/exhaustive-deps': 'warn',
35-
36-
'@typescript-eslint/ban-ts-comment': [
37-
'error',
38-
{ 'ts-check': true, 'ts-expect-error': false },
39-
],
40-
'@typescript-eslint/no-unused-vars': [
41-
'error',
42-
{ argsIgnorePattern: '^_', ignoreRestSiblings: true },
43-
],
44-
45-
'@typescript-eslint/no-base-to-string': 'error',
46-
'@typescript-eslint/no-explicit-any': 'error',
47-
'@typescript-eslint/no-non-null-assertion': 'error',
48-
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'error',
49-
'@typescript-eslint/no-unnecessary-condition': 'error',
50-
'@typescript-eslint/no-unnecessary-qualifier': 'error',
51-
'@typescript-eslint/no-unnecessary-type-arguments': 'error',
52-
'@typescript-eslint/prefer-nullish-coalescing': 'error',
53-
'@typescript-eslint/prefer-optional-chain': 'error',
54-
'@typescript-eslint/strict-boolean-expressions': 'error',
55-
},
3+
extends: '@react-native-community',
564
};

package-lock.json

Lines changed: 135 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
},
7777
"devDependencies": {
7878
"@commitlint/config-conventional": "^17.0.2",
79+
"@faker-js/faker": "^9.7.0",
7980
"@react-native-community/cli": "15.0.1",
8081
"@react-native/babel-preset": "^0.79.1",
8182
"@react-native/eslint-config": "^0.79.1",
@@ -96,8 +97,7 @@
9697
"eslint": "^8.57.1",
9798
"eslint-plugin-react-hooks": "^4.6.2",
9899
"expo": "^53.0.0-preview.7",
99-
"faker": "^6.6.6",
100-
"fetch-mock": "^12.5.2",
100+
"fetch-mock": "^7.7.3",
101101
"husky": "^9.1.7",
102102
"jest": "^29.7.0",
103103
"jest-environment-jsdom": "^29.7.0",
@@ -135,7 +135,8 @@
135135
"modulePathIgnorePatterns": [
136136
"fixtures",
137137
"<rootDir>/example/node_modules",
138-
"<rootDir>/lib/"
138+
"<rootDir>/lib/",
139+
"<rootDir>/node_modules/(?!fetch-mock)/"
139140
]
140141
},
141142
"commitlint": {

src/hooks/__tests__/use-auth0.spec.jsx

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,12 +1000,19 @@ describe('The useAuth0 hook', () => {
10001000
);
10011001
mockAuth0.credentialsManager.clearCredentials.mockResolvedValue();
10021002

1003-
result.current.clearCredentials();
1004-
await waitFor(() => expect(result.current.isLoading).toBe(false));
1005-
expect(result.current.error).toBe(errorToThrow);
1006-
result.current.clearCredentials();
1007-
await waitFor(() => expect(result.current.isLoading).toBe(false));
1008-
expect(result.current.error).toBeNull();
1003+
// First call will fail and set an error
1004+
await act(async () => {
1005+
await result.current.clearCredentials();
1006+
});
1007+
1008+
await waitFor(() => expect(result.current.error).toBe(errorToThrow));
1009+
1010+
// Second call should succeed and clear the error
1011+
await act(async () => {
1012+
await result.current.clearCredentials();
1013+
});
1014+
1015+
await waitFor(() => expect(result.current.error).toBeNull());
10091016
});
10101017

10111018
it('sets the error property when an error is raised in authorize', async () => {
@@ -1126,8 +1133,17 @@ describe('The useAuth0 hook', () => {
11261133
mockAuth0.credentialsManager.getCredentials.mockResolvedValue(
11271134
updatedMockCredentialsWithIdToken
11281135
);
1129-
result.current.getCredentials();
1130-
await waitFor(() => expect(result.current.isLoading).toBe(false));
1136+
1137+
// Use act to handle the state update
1138+
await act(async () => {
1139+
await result.current.getCredentials();
1140+
});
1141+
1142+
// Now wait for the user to be updated before checking
1143+
await waitFor(() =>
1144+
expect(result.current.user?.name).toBe('Different User')
1145+
);
1146+
11311147
expect(result.current.user).toMatchObject({
11321148
name: 'Different User',
11331149
familyName: 'User',

0 commit comments

Comments
 (0)