|
| 1 | +import { editFile, isBuild, untilUpdated } from '../../testUtils' |
| 2 | + |
| 3 | +test('should render', async () => { |
| 4 | + expect(await page.textContent('.named')).toMatch('0') |
| 5 | + expect(await page.textContent('.named-specifier')).toMatch('1') |
| 6 | + expect(await page.textContent('.default')).toMatch('2') |
| 7 | + expect(await page.textContent('.default-tsx')).toMatch('3') |
| 8 | +}) |
| 9 | + |
| 10 | +test('should update', async () => { |
| 11 | + await page.click('.named') |
| 12 | + expect(await page.textContent('.named')).toMatch('1') |
| 13 | + await page.click('.named-specifier') |
| 14 | + expect(await page.textContent('.named-specifier')).toMatch('2') |
| 15 | + await page.click('.default') |
| 16 | + expect(await page.textContent('.default')).toMatch('3') |
| 17 | + await page.click('.default-tsx') |
| 18 | + expect(await page.textContent('.default-tsx')).toMatch('4') |
| 19 | +}) |
| 20 | + |
| 21 | +if (!isBuild) { |
| 22 | + test('hmr: named export', async () => { |
| 23 | + editFile('Comps.jsx', (code) => |
| 24 | + code.replace('named {count', 'named updated {count') |
| 25 | + ) |
| 26 | + await untilUpdated(() => page.textContent('.named'), 'named updated 0') |
| 27 | + |
| 28 | + // should not affect other components on the page |
| 29 | + expect(await page.textContent('.named-specifier')).toMatch('2') |
| 30 | + expect(await page.textContent('.default')).toMatch('3') |
| 31 | + expect(await page.textContent('.default-tsx')).toMatch('4') |
| 32 | + }) |
| 33 | + |
| 34 | + test('hmr: named export via specifier', async () => { |
| 35 | + editFile('Comps.jsx', (code) => |
| 36 | + code.replace('named specifier {count', 'named specifier updated {count') |
| 37 | + ) |
| 38 | + await untilUpdated( |
| 39 | + () => page.textContent('.named-specifier'), |
| 40 | + 'named specifier updated 1' |
| 41 | + ) |
| 42 | + |
| 43 | + // should not affect other components on the page |
| 44 | + expect(await page.textContent('.default')).toMatch('3') |
| 45 | + expect(await page.textContent('.default-tsx')).toMatch('4') |
| 46 | + }) |
| 47 | + |
| 48 | + test('hmr: default export', async () => { |
| 49 | + editFile('Comps.jsx', (code) => |
| 50 | + code.replace('default {count', 'default updated {count') |
| 51 | + ) |
| 52 | + await untilUpdated(() => page.textContent('.default'), 'default updated 2') |
| 53 | + |
| 54 | + // should not affect other components on the page |
| 55 | + expect(await page.textContent('.default-tsx')).toMatch('4') |
| 56 | + }) |
| 57 | + |
| 58 | + test('hmr: named export via specifier', async () => { |
| 59 | + // update another component |
| 60 | + await page.click('.named') |
| 61 | + expect(await page.textContent('.named')).toMatch('1') |
| 62 | + |
| 63 | + editFile('Comp.tsx', (code) => |
| 64 | + code.replace('default tsx {count', 'default tsx updated {count') |
| 65 | + ) |
| 66 | + await untilUpdated( |
| 67 | + () => page.textContent('.default-tsx'), |
| 68 | + 'default tsx updated 3' |
| 69 | + ) |
| 70 | + |
| 71 | + // should not affect other components on the page |
| 72 | + expect(await page.textContent('.named')).toMatch('1') |
| 73 | + }) |
| 74 | +} |
0 commit comments