UNPKG

html2canvas-pro

Version:

Screenshots with JavaScript. Next generation!

109 lines 4.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const assert_1 = require("assert"); const element_container_1 = require("../element-container"); const context_1 = require("../../core/context"); const bounds_1 = require("../../css/layout/bounds"); const config_1 = require("../../config"); describe('ElementContainer', () => { let context; let mockElement; beforeEach(() => { const mockWindow = { document: { createElement: (_name) => { let _href = ''; return { set href(value) { _href = value; }, get href() { return _href; }, get protocol() { return 'http:'; }, get hostname() { return 'localhost'; }, get port() { return ''; } }; } }, location: { href: 'http://localhost/' }, getComputedStyle: () => ({ animationDuration: '1s', transform: 'rotate(45deg)', rotate: '45deg', display: 'block', position: 'static' }) }; const config = new config_1.Html2CanvasConfig({ window: mockWindow }); context = new context_1.Context({ logging: false, imageTimeout: 15000, useCORS: false, allowTaint: false }, new bounds_1.Bounds(0, 0, 800, 600), config); mockElement = { nodeType: 1, tagName: 'DIV', style: { animationDuration: '1s', transform: 'rotate(45deg)', rotate: '45deg' }, getAttribute: () => null, getBoundingClientRect: () => ({ left: 0, top: 0, width: 100, height: 100, right: 100, bottom: 100 }) }; }); it('should normalize DOM by default', () => { const container = new element_container_1.ElementContainer(context, mockElement); (0, assert_1.ok)(container.styles); (0, assert_1.ok)(container.bounds); // DOM should be normalized (animationDuration set to '0s') (0, assert_1.strictEqual)(mockElement.style.animationDuration, '0s'); }); it('should not normalize DOM when normalizeDom is false', () => { const originalAnimation = mockElement.style.animationDuration; const options = { normalizeDom: false }; const container = new element_container_1.ElementContainer(context, mockElement, options); (0, assert_1.ok)(container.styles); (0, assert_1.ok)(container.bounds); // DOM should NOT be normalized (0, assert_1.strictEqual)(mockElement.style.animationDuration, originalAnimation); }); it('should support explicit normalizeDom: true', () => { const options = { normalizeDom: true }; const container = new element_container_1.ElementContainer(context, mockElement, options); (0, assert_1.ok)(container.styles); (0, assert_1.ok)(container.bounds); (0, assert_1.strictEqual)(mockElement.style.animationDuration, '0s'); }); it('should initialize empty arrays for textNodes and elements', () => { const container = new element_container_1.ElementContainer(context, mockElement); (0, assert_1.ok)(Array.isArray(container.textNodes)); (0, assert_1.ok)(Array.isArray(container.elements)); (0, assert_1.strictEqual)(container.textNodes.length, 0); (0, assert_1.strictEqual)(container.elements.length, 0); }); it('should initialize flags to 0', () => { const container = new element_container_1.ElementContainer(context, mockElement); (0, assert_1.strictEqual)(container.flags, 0); }); }); //# sourceMappingURL=element-container.test.js.map