1.0.0 • Published 4 years ago
@lunit/use-control-log v1.0.0
Sample Codes
https://lunit-io.github.io/opt-tool-frontend
Stories
Tests
__tests__/useControlLog.test.ts
import { act, renderHook } from '@testing-library/react-hooks';
import { useControlLog } from '../useControlLog';
describe('useControlLog()', () => {
test('addControlLog', () => {
const { result, rerender } = renderHook(({ sessionId }) => useControlLog(sessionId), {
initialProps: {
sessionId: 'session1',
},
});
expect(result.current.controlLog.current).toHaveLength(0);
act(() => {
result.current.addControlLog({ command: 'a' });
result.current.addControlLog({ command: 'b' });
});
expect(result.current.controlLog.current).toHaveLength(2);
act(() => {
result.current.addControlLog({ command: 'c' });
result.current.addControlLog({ command: 'd' });
});
expect(result.current.controlLog.current).toHaveLength(4);
expect(result.current.controlLog.current!.map(({ command }) => command).join('')).toBe('abcd');
rerender({
sessionId: 'session2',
});
expect(result.current.controlLog.current).toHaveLength(0);
});
});
__tests__/useControlLog.test.ts
import { act, renderHook } from '@testing-library/react-hooks';
import { useControlLog } from '../useControlLog';
describe('useControlLog()', () => {
test('addControlLog', () => {
const { result, rerender } = renderHook(({ sessionId }) => useControlLog(sessionId), {
initialProps: {
sessionId: 'session1',
},
});
expect(result.current.controlLog.current).toHaveLength(0);
act(() => {
result.current.addControlLog({ command: 'a' });
result.current.addControlLog({ command: 'b' });
});
expect(result.current.controlLog.current).toHaveLength(2);
act(() => {
result.current.addControlLog({ command: 'c' });
result.current.addControlLog({ command: 'd' });
});
expect(result.current.controlLog.current).toHaveLength(4);
expect(result.current.controlLog.current!.map(({ command }) => command).join('')).toBe('abcd');
rerender({
sessionId: 'session2',
});
expect(result.current.controlLog.current).toHaveLength(0);
});
});
5.0.0-alpha.4
4 years ago
5.0.0-alpha.3
4 years ago
5.0.0-alpha.2
4 years ago
5.0.0-alpha.1
4 years ago
1.0.0
4 years ago