-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9433d6b
commit 1257c74
Showing
7 changed files
with
60 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,43 @@ | ||
/* eslint-disable jest/no-conditional-expect */ | ||
import TestRenderer from 'react-test-renderer'; | ||
import { screen, render, waitFor } from '@testing-library/react'; | ||
import RunWeb from '../'; | ||
|
||
it('Should output a RunWeb', async () => { | ||
const component = TestRenderer.create(<RunWeb />); | ||
let tree = component.toJSON(); | ||
if (tree && !Array.isArray(tree)) { | ||
expect(tree.type).toEqual('iframe'); | ||
expect(tree.props.title).toEqual('Demo Title'); | ||
expect(tree.props.width).toEqual('100%'); | ||
expect(tree.props.height).toEqual('100%'); | ||
expect(tree.props.style).toEqual({ border: 0 }); | ||
expect(tree.props.srcDoc).toBeUndefined(); | ||
} | ||
global.URL.createObjectURL = jest.fn((url) => { | ||
return ''; | ||
}); | ||
|
||
it('renders <RunWeb /> test case', async () => { | ||
const { debug } = render(<RunWeb data-testid="iframe" />); | ||
await waitFor(() => { | ||
const iframe = screen.getByTestId('iframe'); | ||
expect(iframe).toHaveProperty('srcdoc', '<!DOCTYPE html><html><head></head><body></body></html>'); | ||
expect(iframe).toHaveProperty('style.border', '0px'); | ||
expect(iframe).toHaveProperty('title', 'Demo Title'); | ||
expect(iframe).toHaveProperty('width', '100%'); | ||
expect(iframe).toHaveProperty('height', '100%'); | ||
}); | ||
}); | ||
|
||
it('RunWeb Props js="..."', async () => { | ||
const component = TestRenderer.create(<RunWeb js="console.log('hello world!')" />); | ||
let tree = component.toJSON(); | ||
if (tree && !Array.isArray(tree)) { | ||
expect(tree.type).toEqual('iframe'); | ||
expect(tree.props.title).toEqual('Demo Title'); | ||
expect(tree.props.width).toEqual('100%'); | ||
expect(tree.props.height).toEqual('100%'); | ||
expect(tree.props.style).toEqual({ border: 0 }); | ||
expect(tree.props.srcDoc).toBeUndefined(); | ||
} | ||
const { debug } = render(<RunWeb data-testid="iframe" title="Example" js="console.log('hello world!')" />); | ||
await waitFor(() => { | ||
// debug() | ||
const iframe = screen.getByTestId('iframe'); | ||
expect(iframe).toHaveProperty('srcdoc', '<!DOCTYPE html><html><head></head><body></body></html>'); | ||
expect(iframe).toHaveProperty('style.border', '0px'); | ||
expect(iframe).toHaveProperty('title', 'Example'); | ||
expect(iframe).toHaveProperty('width', '100%'); | ||
expect(iframe).toHaveProperty('height', '100%'); | ||
}); | ||
}); | ||
|
||
it('RunWeb Props css="..."', async () => { | ||
const component = TestRenderer.create(<RunWeb css="body { color:red; }" />); | ||
let tree = component.toJSON(); | ||
if (tree && !Array.isArray(tree)) { | ||
expect(tree.type).toEqual('iframe'); | ||
expect(tree.props.title).toEqual('Demo Title'); | ||
expect(tree.props.width).toEqual('100%'); | ||
expect(tree.props.height).toEqual('100%'); | ||
expect(tree.props.style).toEqual({ border: 0 }); | ||
expect(tree.props.srcDoc).toBeUndefined(); | ||
} | ||
const { debug } = render(<RunWeb data-testid="iframe" css="body { color:red; }" />); | ||
await waitFor(() => { | ||
const iframe = screen.getByTestId('iframe'); | ||
expect(iframe).toHaveProperty('srcdoc', '<!DOCTYPE html><html><head></head><body></body></html>'); | ||
expect(iframe).toHaveProperty('style.border', '0px'); | ||
expect(iframe).toHaveProperty('title', 'Demo Title'); | ||
expect(iframe).toHaveProperty('width', '100%'); | ||
expect(iframe).toHaveProperty('height', '100%'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters