--- /dev/null
+import { makeInstance, ForeignObject } from '../../../src/main.js';
+
+const { any, createSpy, objectContaining } = jasmine
+
+
+describe('ForeignObject.js', () => {
+
+ describe('()', () => {
+ it('creates a new object of type ForeignObject', () => {
+ expect(new ForeignObject()).toEqual(any(ForeignObject))
+ })
+
+ it('sets passed attributes on the element', () => {
+ expect(new ForeignObject({id:'foo'}).id()).toBe('foo')
+ })
+ })
+
+ describe('Container', () => {
+ describe('foreignObject()', () => {
+ it('creates a foreignObject in the container', () => {
+ const canvas = makeInstance().addTo('#canvas')
+ const foreignObject = canvas.foreignObject()
+ expect(foreignObject).toEqual(any(ForeignObject))
+ expect(foreignObject.parent()).toBe(canvas)
+ })
+
+ it('sets width and height correctly on construction', () => {
+ const canvas = makeInstance().addTo('#canvas')
+ const foreignObject = canvas.foreignObject(100, 200)
+ expect(foreignObject.width()).toBe(100)
+ expect(foreignObject.height()).toBe(200)
+ })
+ })
+ })
+
+ describe('Element methods', () => {
+ it('is usable with Elements methods such as height() and width()', () => {
+ const canvas = makeInstance().addTo('#canvas')
+ const foreignObject = canvas.foreignObject()
+ foreignObject.width(100).height(200).x(10).y(20)
+ expect(foreignObject.width()).toBe(100)
+ expect(foreignObject.height()).toBe(200)
+ expect(foreignObject.x()).toBe(10)
+ expect(foreignObject.y()).toBe(20)
+ })
+ })
+})
--- /dev/null
+import { nodeOrNew, register, wrapWithAttrCheck } from '../utils/adopter.js'
+import { registerMethods } from '../utils/methods.js'
+import Element from './Element.js'
+
+export default class ForeignObject extends Element {
+ constructor (node) {
+ super(nodeOrNew('foreignObject', node), node)
+ }
+}
+
+registerMethods({
+ Container: {
+ foreignObject: wrapWithAttrCheck(function (width, height) {
+ return this.put(new ForeignObject()).size(width, height)
+ })
+ }
+})
+
+register(ForeignObject)
export { default as Dom } from './elements/Dom.js'
export { default as Element } from './elements/Element.js'
export { default as Ellipse } from './elements/Ellipse.js'
+export { default as ForeignObject } from './elements/ForeignObject.js'
export { default as Gradient } from './elements/Gradient.js'
export { default as G } from './elements/G.js'
export { default as A } from './elements/A.js'