/* global jasmine */ /* eslint-env jest */ import { sandbox } from './helpers' jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5 test('basic: can edit a component without losing state', async () => { const [session, cleanup] = await sandbox() await session.patch( 'index.js', ` import { useCallback, useState } from 'react' export default function Index() { const [count, setCount] = useState(0) const increment = useCallback(() => setCount(c => c + 1), [setCount]) return (

{count}

) } ` ) await session.evaluate(() => document.querySelector('button').click()) expect( await session.evaluate(() => document.querySelector('p').textContent) ).toBe('1') await session.patch( 'index.js', ` import { useCallback, useState } from 'react' export default function Index() { const [count, setCount] = useState(0) const increment = useCallback(() => setCount(c => c + 1), [setCount]) return (

Count: {count}

) } ` ) expect( await session.evaluate(() => document.querySelector('p').textContent) ).toBe('Count: 1') await session.evaluate(() => document.querySelector('button').click()) expect( await session.evaluate(() => document.querySelector('p').textContent) ).toBe('Count: 2') await cleanup() }) test('can recover from a syntax error without losing state', async () => { const [session, cleanup] = await sandbox() await session.patch( 'index.js', ` import { useCallback, useState } from 'react' export default function Index() { const [count, setCount] = useState(0) const increment = useCallback(() => setCount(c => c + 1), [setCount]) return (

{count}

) } ` ) await session.evaluate(() => document.querySelector('button').click()) expect( await session.evaluate(() => document.querySelector('p').textContent) ).toBe('1') await session.patch('index.js', `export default () =>
setCount(c => c + 1), [setCount]) return (

Count: {count}

) } ` ) expect( await session.evaluate(() => document.querySelector('p').textContent) ).toBe('Count: 1') await cleanup() })