mirror of
https://github.com/uetchy/namae.git
synced 2025-03-17 04:30:31 +09:00
test: add test for utils
This commit is contained in:
parent
a7efe886ab
commit
80d6270799
@ -3,6 +3,7 @@
|
||||
"description": "namae saves your time searching around registries and checking if the desired name is ready for use.",
|
||||
"author": "Yasuaki Uechi <y@uechi.io> (https://uechi.io/)",
|
||||
"scripts": {
|
||||
"dev": " yarn start",
|
||||
"postinstall": "yarn --cwd web && yarn --cwd api",
|
||||
"ship": "now",
|
||||
"start": "now dev",
|
||||
|
20
web/src/util/hooks.test.tsx
Normal file
20
web/src/util/hooks.test.tsx
Normal file
@ -0,0 +1,20 @@
|
||||
import React from 'react';
|
||||
import {render, waitForDomChange} from '@testing-library/react';
|
||||
import {useDeferredState} from './hooks';
|
||||
|
||||
const App: React.FC = () => {
|
||||
const [value, setValue] = useDeferredState(500, 0);
|
||||
React.useEffect(() => {
|
||||
setValue(1);
|
||||
setValue(2);
|
||||
setValue(3);
|
||||
}, [setValue]);
|
||||
return <div data-testid="root">{value}</div>;
|
||||
};
|
||||
|
||||
it('provoke state flow after certain time passed', async () => {
|
||||
const {container, getByTestId} = render(<App />);
|
||||
expect(getByTestId('root').textContent).toBe('0');
|
||||
await waitForDomChange({container});
|
||||
expect(getByTestId('root').textContent).toBe('3');
|
||||
});
|
5
web/src/util/pwa.test.ts
Normal file
5
web/src/util/pwa.test.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import {isStandalone} from './pwa';
|
||||
|
||||
it('recognize standalone mode', () => {
|
||||
expect(isStandalone()).toEqual(false);
|
||||
});
|
9
web/src/util/text.test.ts
Normal file
9
web/src/util/text.test.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import {capitalize} from './text';
|
||||
|
||||
it('capitalize text', () => {
|
||||
expect(capitalize('test')).toEqual('Test');
|
||||
expect(capitalize('Test')).toEqual('Test');
|
||||
expect(capitalize('tEST')).toEqual('Test');
|
||||
expect(capitalize('TEST')).toEqual('Test');
|
||||
expect(capitalize('')).toEqual('');
|
||||
});
|
@ -1,3 +1,4 @@
|
||||
export function capitalize(text: string) {
|
||||
if (text.length === 0) return '';
|
||||
return text[0].toUpperCase() + text.slice(1).toLowerCase();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user