mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-04-22 19:58:25 +08:00
Adds support for opening external URLs in a new tab/window. Includes patches to 'Text' to improve accessibility and 'createDOMElement' to improve external link security. Fix #198
60 lines
2.2 KiB
JavaScript
60 lines
2.2 KiB
JavaScript
/* eslint-env jasmine, jest */
|
|
|
|
import createDOMElement from '..';
|
|
import renderer from 'react-test-renderer';
|
|
|
|
describe('modules/createDOMElement', () => {
|
|
test('renders correct DOM element', () => {
|
|
let component = renderer.create(createDOMElement('span'));
|
|
expect(component.toJSON()).toMatchSnapshot();
|
|
component = renderer.create(createDOMElement('main'));
|
|
expect(component.toJSON()).toMatchSnapshot();
|
|
});
|
|
|
|
test('prop "accessibilityLabel"', () => {
|
|
const accessibilityLabel = 'accessibilityLabel';
|
|
const component = renderer.create(createDOMElement('span', { accessibilityLabel }));
|
|
expect(component.toJSON()).toMatchSnapshot();
|
|
});
|
|
|
|
test('prop "accessibilityLiveRegion"', () => {
|
|
const accessibilityLiveRegion = 'polite';
|
|
const component = renderer.create(createDOMElement('span', { accessibilityLiveRegion }));
|
|
expect(component.toJSON()).toMatchSnapshot();
|
|
});
|
|
|
|
describe('prop "accessibilityRole"', () => {
|
|
test('roles', () => {
|
|
const component = renderer.create(createDOMElement('span', { accessibilityRole: 'banner' }));
|
|
expect(component.toJSON()).toMatchSnapshot();
|
|
});
|
|
|
|
test('button', () => {
|
|
const component = renderer.create(createDOMElement('span', { accessibilityRole: 'button' }));
|
|
expect(component.toJSON()).toMatchSnapshot();
|
|
});
|
|
|
|
test('link and target="_blank"', () => {
|
|
const component = renderer.create(createDOMElement('span', { accessibilityRole: 'link', target: '_blank' }));
|
|
expect(component.toJSON()).toMatchSnapshot();
|
|
});
|
|
});
|
|
|
|
test('prop "accessible"', () => {
|
|
// accessible (implicit)
|
|
let component = renderer.create(createDOMElement('span', {}));
|
|
expect(component.toJSON()).toMatchSnapshot();
|
|
// accessible (explicit)
|
|
component = renderer.create(createDOMElement('span', { accessible: true }));
|
|
expect(component.toJSON()).toMatchSnapshot();
|
|
// not accessible
|
|
component = renderer.create(createDOMElement('span', { accessible: false }));
|
|
expect(component.toJSON()).toMatchSnapshot();
|
|
});
|
|
|
|
test('prop "testID"', () => {
|
|
const component = renderer.create(createDOMElement('span', { testID: 'Example.testID' }));
|
|
expect(component.toJSON()).toMatchSnapshot();
|
|
});
|
|
});
|