Skip to content

Instantly share code, notes, and snippets.

View Renaud009's full-sized avatar

Renaud Hébert-Legault Renaud009

  • CRIM
  • Montréal, QC, Canada
View GitHub Profile
import { graphql, GraphQLContext, GraphQLRequest, ResponseResolver } from 'msw';
import { api } from '../../../services/graphqlApi.generated';
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
export type Scalars = {
String: string;
};
export type GetSomethingQueryVariables = Exact<{
id: Scalars['String'];
}>;
@Renaud009
Renaud009 / AnyComponent.test.tsx
Last active October 24, 2022 21:14
waitFor resolver
import { waitFor } from '@testing-library/react';
import { server } from '../../../../test/mocks/server';
import { generateSomething } from '../../test/fixtures/something.fixture';
import { renderWrapper } from '../../test/helpers/renderWrapper';
import { AnyComponent } from './AnyComponent';
describe('Rendering any component with `renderWrapper`', () => {
it('should wait for msw resolver to execute', async () => {
const getSomethingResolver: Parameters<typeof mockGetSomethingQuery>[0] = jest.fn(
(_req, res, ctx) => res(ctx.data({ getSomething: generateSomething()})),
@Renaud009
Renaud009 / package.json
Created October 21, 2022 19:50
codegen script in package.json
{
"scripts": {
"generate-gql": "graphql-codegen --config codegen.yml",
}
}
@Renaud009
Renaud009 / codegen.yml
Last active October 21, 2022 19:47
Graphql codegen config
overwrite: true
schema: 'https://{{LOCAL_API_ENDPOINT}}:3443/graphql'
generates:
src/services/graphqlApi.generated.ts:
documents: 'src/services/graphql/*.graphql'
plugins:
- 'typescript'
- 'typescript-operations'
- 'typescript-msw'
- typescript-rtk-query:
@Renaud009
Renaud009 / test.js
Last active June 14, 2018 15:34
Test
const uniqSort = function(arr) {
const bread = {};
const result = [arr[0]];
for (let i = 1; i < arr.length; i++) {
if(!bread[arr[i]] {
result.push(arr[i]);
bread[arr[i]] = true;
}
}
return result.sort((a,b) => a - b);