Skip to content

Commit fa8dde3

Browse files
authored
Merge pull request #24 from oslabs-beta/john/testingLibrary
John/testing library
2 parents 738ebec + c832bf8 commit fa8dde3

File tree

13 files changed

+2050
-248
lines changed

13 files changed

+2050
-248
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ Contributions are always welcome. Please create a fork from https://github.com/o
4343
4. `npm run link-package`
4444
1. Links React Query Rewind
4545
5. `npm run example-1`
46-
1. Starts the example server with webpack
46+
1. Starts the example server with webpack

__tests__/index.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
import ReactQueryRewind from '../src/index'
3+
import { render } from '@testing-library/react';
4+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
5+
6+
7+
describe('Renders when a query client is provided', () => {
8+
// mock query client
9+
const queryClient = new QueryClient();
10+
11+
// we **might** want to add clean error handling for developers to ensure the component fails gracefully
12+
// This fails if I don't create a query client and wrap ReactQueryRewind around a QueryClientProvider component and the same thing would happen in production
13+
// Maybe we add try/catch block around the useQueryClient hook within ReactQueryRewind component and send a message to the dev tools alerting the developer that they didn't set up the component correctly
14+
15+
it('renders without crashing', () => {
16+
render(
17+
<QueryClientProvider client={queryClient}>
18+
<ReactQueryRewind/>
19+
</QueryClientProvider>
20+
);
21+
});
22+
});

babel.config.cjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
presets:[
3+
'@babel/preset-env',
4+
'@babel/preset-react',
5+
'@babel/preset-typescript'
6+
]
7+
}
8+
Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,11 @@
11
{
22
"posts": [
33
{
4-
"text": "test",
4+
"text": "new",
55
"liked": false,
66
"comments": [],
77
"createComment": false,
8-
"timestamp": "7:25 PM"
9-
},
10-
{
11-
"text": "new",
12-
"liked": true,
13-
"comments": [
14-
"hi",
15-
"hi"
16-
],
17-
"createComment": true,
18-
"timestamp": "5:59 PM"
19-
},
20-
{
21-
"text": "feed 2",
22-
"liked": true,
23-
"comments": [
24-
"comment",
25-
"comment 1",
26-
"comment 2",
27-
"hi"
28-
],
29-
"createComment": true,
30-
"timestamp": "7:02 PM"
8+
"timestamp": "1:17 PM"
319
}
3210
]
3311
}

jest.config.cjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = {
2+
// Automatically clear mock calls and instances between every test
3+
clearMocks: true,
4+
5+
// The test environment that will be used for testing
6+
testEnvironment: "jsdom",
7+
8+
// The glob patterns Jest uses to detect test files
9+
testMatch: [
10+
"**/__tests__/**/*.[jt]s?(x)",
11+
"**/?(*.)+(spec|test).[tj]s?(x)"
12+
],
13+
14+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
15+
testPathIgnorePatterns: [
16+
"/node_modules/"
17+
],
18+
19+
// A map from regular expressions to paths to transformers
20+
transform: {
21+
"^.+\\.(js|jsx|ts|tsx)$": "babel-jest"
22+
},
23+
24+
// Indicates whether each individual test should be reported during the run
25+
verbose: true,
26+
};

0 commit comments

Comments
 (0)