1
0
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:
uetchy 2019-09-24 13:55:43 +09:00
parent a7efe886ab
commit 80d6270799
5 changed files with 36 additions and 0 deletions

View File

@ -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",

View 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
View File

@ -0,0 +1,5 @@
import {isStandalone} from './pwa';
it('recognize standalone mode', () => {
expect(isStandalone()).toEqual(false);
});

View 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('');
});

View File

@ -1,3 +1,4 @@
export function capitalize(text: string) {
if (text.length === 0) return '';
return text[0].toUpperCase() + text.slice(1).toLowerCase();
}