Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/modern-pens-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-loqate': patch
---

Update test dependencies and fix all test warnings
File renamed without changes.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "react-loqate",
"version": "3.0.1",
"type": "module",
"license": "MIT",
"author": "Bram Kaashoek",
"main": "dist/index.js",
Expand Down Expand Up @@ -61,25 +62,24 @@
"@storybook/test": "8.0.8",
"@testing-library/jest-dom": "6.4.2",
"@testing-library/react": "15.0.2",
"@testing-library/react-hooks": "8.0.1",
"@testing-library/user-event": "^14.5.2",
"@types/react": "18.0.27",
"@types/react-dom": "18.0.10",
"@typescript-eslint/eslint-plugin": "7.7.0",
"@vitest/coverage-v8": "1.2.1",
"@vitest/coverage-v8": "3.2.4",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-storybook": "0.8.0",
"husky": "9.0.11",
"jsdom": "21.1.0",
"lint-staged": "^15.2.2",
"msw": "2.2.14",
"msw": "2.11.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"storybook": "8.0.8",
"tslib": "2.4.1",
"tsup": "8.0.2",
"typescript": "4.9.4",
"vitest": "1.2.1"
"vitest": "3.2.4"
},
"peerDependencies": {
"react": ">=18",
Expand Down
695 changes: 330 additions & 365 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions src/utils/Loqate.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fetch } from 'cross-fetch';
import { describe, expect, it } from 'vitest';
import { LoqateError } from '../error';
import { server } from '../server';
import { biasHandler, errorHandler } from '../serverHandlers';
import { selection } from '../testing/fixtures/selection';
Expand Down Expand Up @@ -79,15 +80,15 @@ describe('Loqate', () => {
limit: 10,
containerId: 'some-container-id',
});
}).rejects.toThrowError(new Error('Unknown key'));
}).rejects.toThrowError('Unknown key');
});

it('should throw loqate errors', async () => {
server.use(errorHandler);

const loqate = Loqate.create('some-key');

let error;
let error: unknown;
try {
await loqate.find({
text: 'some-text',
Expand All @@ -100,7 +101,8 @@ describe('Loqate', () => {
error = e;
}

expect(error).toEqual(new Error('Unknown key'));
expect(error).toBeInstanceOf(LoqateError);
expect((error as LoqateError).message).toBe('Unknown key');
expect(JSON.stringify(error)).toEqual(
JSON.stringify({
Cause: 'The key you are using to access the service was not found.',
Expand Down
15 changes: 11 additions & 4 deletions src/utils/Portal.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { render, screen } from '@testing-library/react';
import { render, screen, act } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React, { type ReactPortal, useEffect, useState } from 'react';
import { createPortal } from 'react-dom';
import { beforeEach, expect, it, vi } from 'vitest';
Expand Down Expand Up @@ -192,14 +193,20 @@ it('waits for mounting before creating portal', async () => {
);
};

render(<TestComponent />);
await act(async () => {
render(<TestComponent />);
});

expect(mockCreatePortal).not.toHaveBeenCalled();
expect(screen.queryByTestId('delayed-child')).not.toBeInTheDocument();

screen.getByText('Show Portal').click();
await act(async () => {
await userEvent.click(screen.getByText('Show Portal'));
});

await screen.findByTestId('delayed-child');
await act(async () => {
await screen.findByTestId('delayed-child');
});

expect(mockCreatePortal).toHaveBeenCalledTimes(1);
});
4 changes: 2 additions & 2 deletions src/utils/useDebounceEffect.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { renderHook } from '@testing-library/react-hooks';
import { renderHook, waitFor } from '@testing-library/react';
import { expect, it, vi } from 'vitest';
import useDebounceEffect from './useDebounceEffect';

it('should debounce the effect', async () => {
const effectFn = vi.fn();
const delay = 10;

const { rerender, waitFor } = renderHook(
const { rerender } = renderHook(
({ value }) => useDebounceEffect(effectFn, delay, [value]),
{
initialProps: {
Expand Down
3 changes: 3 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import path from 'path';
import { fileURLToPath } from 'url';
import { defineConfig } from 'vitest/config';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

export default defineConfig({
test: {
setupFiles: ['./vitest.setup.ts'],
Expand Down