123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- import React from '../../src/May'
- var ReactDOM = React;
- describe('SVG元素', function () {
- // this.timeout(200000);
- // before(async () => {
- // await beforeHook()
- // })
- // after(async () => {
- // await afterHook(false)
- // })
- var body = document.body,
- div
- beforeEach(function () {
- div = document.createElement('div')
- body.appendChild(div)
- })
- afterEach(function () {
- body.removeChild(div)
- })
- var rsvg = /^\[object SVG\w*Element\]$/
- it('circle', async () => {
- var s = ReactDOM.render(
- <svg><circle cx='25' cy='25' r='20' fill='green' /></svg>, div)
- expect(rsvg.test(s.firstChild)).toBe(true)
- })
- it('ellipse', async() => {
- var s = ReactDOM.render(
- <svg><ellipse cx='25' cy='25' rx='20' ry='10' fill='green'/></svg>, div)
- expect(rsvg.test(s.firstChild)).toBe(true)
- })
- it('line', async() => {
- var s = ReactDOM.render(
- <svg><line x1='5' y1='5' x2='45' y2='45' stroke='green'/></svg>, div)
- expect(rsvg.test(s.firstChild)).toBe(true)
- })
- it('path', async() => {
- var s = ReactDOM.render(
- <svg><path d='M5,5 C5,45 45,45 45,5' fill="none" stroke='red'/></svg>, div)
- expect(rsvg.test(s.firstChild)).toBe(true)
- })
- it('polygon', async() => {
- var s = ReactDOM.render(
- <svg><polygon points='5,5 45,45 5,45 45,5' fill="none" stroke='red'/></svg>, div)
- expect(rsvg.test(s.firstChild)).toBe(true)
- })
- it('polyline', async() => {
- var s = ReactDOM.render(
- <svg><polyline points='5,5 45,45 5,45 45,5' fill="none" stroke='red'/></svg>, div)
-
- expect(rsvg.test(s.firstChild)).toBe(true)
- })
- it('rect', async() => {
- var s = ReactDOM.render(
- <svg><rect
- x='5'
- y='5'
- rx='5'
- ry='5'
- width='40'
- height='40'
- fill="green"
- stroke='red'/></svg>, div)
- expect(rsvg.test(s.firstChild)).toBe(true)
- })
- it('defs', async() => {
- var s = ReactDOM.render(
- <svg>
- <defs>
- <rect id='rect' style='fill:green' width='15' height='15'/>
- </defs>
- <use x='5' y='5' xlinkHref='#rect'/>
- <use x='30' y='30' xlinkHref='#rect'/>
- </svg>, div)
- expect(rsvg.test(s.firstChild)).toBe(true)
- })
- //svg一般用的不会太复杂,先支持比较简单的
- /*it('attribute throw error', async() => {
- var a = {}
- a.toString = function () {
- throw "xxx"
- }
- var s = ReactDOM.render(React.createElement('div', {aaa: a}), div)
- expect(s.getAttribute('aaa')).toBeNull()
- })
- it('use元素的xlinkHref', async() => {
- function Test() {
- return (
- <svg className="icon-twitter" width="16px" height="16px">
- <use xlinkHref="#twitter" xlinkRole="#aaa" id='aaa'/>
- </svg>
- )
- }
- ReactDOM.render(
- <Test/>, div)
- var el = div.getElementsByTagName('use')
- expect(el.length).toBe(1)
- expect(el[0].getAttribute('xlink:href')).toBe('#twitter')
- expect(el[0].getAttribute('xlink:role')).toBe('#aaa')
- })*/
- })
|