|
1 | | -/* eslint-disable jest/no-conditional-expect */ |
2 | | -import TestRenderer from 'react-test-renderer'; |
| 1 | +import { screen, render, waitFor } from '@testing-library/react'; |
3 | 2 | import RunWeb from '../'; |
4 | 3 |
|
5 | | -it('Should output a RunWeb', async () => { |
6 | | - const component = TestRenderer.create(<RunWeb />); |
7 | | - let tree = component.toJSON(); |
8 | | - if (tree && !Array.isArray(tree)) { |
9 | | - expect(tree.type).toEqual('iframe'); |
10 | | - expect(tree.props.title).toEqual('Demo Title'); |
11 | | - expect(tree.props.width).toEqual('100%'); |
12 | | - expect(tree.props.height).toEqual('100%'); |
13 | | - expect(tree.props.style).toEqual({ border: 0 }); |
14 | | - expect(tree.props.srcDoc).toBeUndefined(); |
15 | | - } |
| 4 | +global.URL.createObjectURL = jest.fn((url) => { |
| 5 | + return ''; |
| 6 | +}); |
| 7 | + |
| 8 | +it('renders <RunWeb /> test case', async () => { |
| 9 | + const { debug } = render(<RunWeb data-testid="iframe" />); |
| 10 | + await waitFor(() => { |
| 11 | + const iframe = screen.getByTestId('iframe'); |
| 12 | + expect(iframe).toHaveProperty('srcdoc', '<!DOCTYPE html><html><head></head><body></body></html>'); |
| 13 | + expect(iframe).toHaveProperty('style.border', '0px'); |
| 14 | + expect(iframe).toHaveProperty('title', 'Demo Title'); |
| 15 | + expect(iframe).toHaveProperty('width', '100%'); |
| 16 | + expect(iframe).toHaveProperty('height', '100%'); |
| 17 | + }); |
16 | 18 | }); |
17 | 19 |
|
18 | 20 | it('RunWeb Props js="..."', async () => { |
19 | | - const component = TestRenderer.create(<RunWeb js="console.log('hello world!')" />); |
20 | | - let tree = component.toJSON(); |
21 | | - if (tree && !Array.isArray(tree)) { |
22 | | - expect(tree.type).toEqual('iframe'); |
23 | | - expect(tree.props.title).toEqual('Demo Title'); |
24 | | - expect(tree.props.width).toEqual('100%'); |
25 | | - expect(tree.props.height).toEqual('100%'); |
26 | | - expect(tree.props.style).toEqual({ border: 0 }); |
27 | | - expect(tree.props.srcDoc).toBeUndefined(); |
28 | | - } |
| 21 | + const { debug } = render(<RunWeb data-testid="iframe" title="Example" js="console.log('hello world!')" />); |
| 22 | + await waitFor(() => { |
| 23 | + // debug() |
| 24 | + const iframe = screen.getByTestId('iframe'); |
| 25 | + expect(iframe).toHaveProperty('srcdoc', '<!DOCTYPE html><html><head></head><body></body></html>'); |
| 26 | + expect(iframe).toHaveProperty('style.border', '0px'); |
| 27 | + expect(iframe).toHaveProperty('title', 'Example'); |
| 28 | + expect(iframe).toHaveProperty('width', '100%'); |
| 29 | + expect(iframe).toHaveProperty('height', '100%'); |
| 30 | + }); |
29 | 31 | }); |
30 | 32 |
|
31 | 33 | it('RunWeb Props css="..."', async () => { |
32 | | - const component = TestRenderer.create(<RunWeb css="body { color:red; }" />); |
33 | | - let tree = component.toJSON(); |
34 | | - if (tree && !Array.isArray(tree)) { |
35 | | - expect(tree.type).toEqual('iframe'); |
36 | | - expect(tree.props.title).toEqual('Demo Title'); |
37 | | - expect(tree.props.width).toEqual('100%'); |
38 | | - expect(tree.props.height).toEqual('100%'); |
39 | | - expect(tree.props.style).toEqual({ border: 0 }); |
40 | | - expect(tree.props.srcDoc).toBeUndefined(); |
41 | | - } |
| 34 | + const { debug } = render(<RunWeb data-testid="iframe" css="body { color:red; }" />); |
| 35 | + await waitFor(() => { |
| 36 | + const iframe = screen.getByTestId('iframe'); |
| 37 | + expect(iframe).toHaveProperty('srcdoc', '<!DOCTYPE html><html><head></head><body></body></html>'); |
| 38 | + expect(iframe).toHaveProperty('style.border', '0px'); |
| 39 | + expect(iframe).toHaveProperty('title', 'Demo Title'); |
| 40 | + expect(iframe).toHaveProperty('width', '100%'); |
| 41 | + expect(iframe).toHaveProperty('height', '100%'); |
| 42 | + }); |
42 | 43 | }); |
0 commit comments