|
4 | 4 | setupTest as upstreamSetupTest, |
5 | 5 | type SetupTestOptions, |
6 | 6 | } from 'ember-qunit'; |
| 7 | +import { getRootElement } from '@ember/test-helpers'; |
7 | 8 |
|
8 | 9 | // This file exists to provide wrappers around ember-qunit's |
9 | 10 | // test setup functions. This way, you can easily extend the setup that is |
@@ -40,4 +41,34 @@ function setupTest(hooks: NestedHooks, options?: SetupTestOptions) { |
40 | 41 | // Additional setup for unit tests can be done here. |
41 | 42 | } |
42 | 43 |
|
43 | | -export { setupApplicationTest, setupRenderingTest, setupTest }; |
| 44 | +function setContainerSize(hooks, width, height, overflow) { |
| 45 | + let initialWidth: number; |
| 46 | + let initialHeight: number; |
| 47 | + let initialOverflow: string; |
| 48 | + |
| 49 | + hooks.beforeEach(function() { |
| 50 | + const container = getRootElement(); // safer than document.getElementById |
| 51 | + |
| 52 | + console.log(container) |
| 53 | + // Store original values |
| 54 | + initialWidth = container.style.width; |
| 55 | + initialHeight = container.style.height; |
| 56 | + initialOverflow = container.style.overflow; |
| 57 | + |
| 58 | + // Set new values |
| 59 | + if (width) container.style.width = width; |
| 60 | + if (height) container.style.height = height; |
| 61 | + if (overflow) container.style.overflow = overflow; |
| 62 | + |
| 63 | + }); |
| 64 | + |
| 65 | + hooks.afterEach(function() { |
| 66 | + const container = getRootElement(); |
| 67 | + // Reset to original values to avoid polluting other tests |
| 68 | + container.style.width = initialWidth; |
| 69 | + container.style.height = initialHeight; |
| 70 | + container.style.height = overflow; |
| 71 | + }); |
| 72 | +} |
| 73 | + |
| 74 | +export { setupApplicationTest, setupRenderingTest, setupTest, setContainerSize }; |
0 commit comments