diff --git a/tests/integration/components/resize-detector-test.js b/tests/integration/components/resize-detector-test.js index a3e65a9..b367a70 100644 --- a/tests/integration/components/resize-detector-test.js +++ b/tests/integration/components/resize-detector-test.js @@ -1,60 +1,66 @@ import Ember from 'ember'; -import { moduleForComponent, test } from 'ember-qunit'; +import { module, test } from 'qunit'; +import { setupRenderingTest } from 'ember-qunit'; +import { render, settled } from '@ember/test-helpers'; import hbs from 'htmlbars-inline-precompile'; -import wait from 'ember-test-helpers/wait'; const { String: { htmlSafe }, run: { later } } = Ember; -moduleForComponent('resize-detector', 'Integration | Component | resize detector', { - integration: true -}); +module('Integration | Component | resize detector', function(hooks) { + setupRenderingTest(hooks); -test('it renders', function(assert) { - // Set any properties with this.set('myProperty', 'value'); - // Handle any actions with this.on('myAction', function(val) { ... }); + hooks.beforeEach(function() { + this.actions = {}; + this.send = (actionName, ...args) => this.actions[actionName].apply(this, args); + }); - this.render(hbs`{{resize-detector}}`); + test('it renders', async function(assert) { + // Set any properties with this.set('myProperty', 'value'); + // Handle any actions with this.on('myAction', function(val) { ... }); - assert.equal(this.$().text().trim(), ''); + await render(hbs`{{resize-detector}}`); - // Template block usage: - this.render(hbs` - {{#resize-detector}} - template block text - {{/resize-detector}} - `); + assert.equal(this.$().text().trim(), ''); - assert.equal(this.$().text().trim(), 'template block text'); -}); + // Template block usage: + await render(hbs` + {{#resize-detector}} + template block text + {{/resize-detector}} + `); -test('it triggers an action when target changes sizes', function(assert){ + assert.equal(this.$().text().trim(), 'template block text'); + }); - assert.expect(2); + test('it triggers an action when target changes sizes', async function(assert) { - this.set('style', htmlSafe('width: 300px; height: 300px;')); + assert.expect(2); - let received; - this.on('resized', function(lastSize){ - received = lastSize; - }); + this.set('style', htmlSafe('width: 300px; height: 300px;')); - this.render(hbs` - {{resize-detector '#square' on-resize=(action 'resized')}} -
- `); + let received; + this.actions.resized = function(lastSize){ + received = lastSize; + }; - later(() => { - assert.deepEqual(received, { width: 300, height: 300 }, 'initial render caused size to be received'); + await render(hbs` + {{resize-detector '#square' on-resize=(action 'resized')}} +
+ `); - this.set('style', htmlSafe('width: 200px; height: 200px;')); - }, 20); + later(() => { + assert.deepEqual(received, { width: 300, height: 300 }, 'initial render caused size to be received'); - later(() => { - assert.deepEqual(received, { width: 200, height: 200 }, 'received updated size'); - }, 70); + this.set('style', htmlSafe('width: 200px; height: 200px;')); + }, 20); - return wait(); + later(() => { + assert.deepEqual(received, { width: 200, height: 200 }, 'received updated size'); + }, 70); + + return settled(); + }); }); \ No newline at end of file diff --git a/tests/unit/services/resize-detector-test.js b/tests/unit/services/resize-detector-test.js index 327c823..0622e3c 100644 --- a/tests/unit/services/resize-detector-test.js +++ b/tests/unit/services/resize-detector-test.js @@ -1,12 +1,12 @@ -import { moduleFor, test } from 'ember-qunit'; +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; -moduleFor('service:resize-detector', 'Unit | Service | resize detector', { - // Specify the other units that are required for this test. - // needs: ['service:foo'] -}); +module('Unit | Service | resize detector', function(hooks) { + setupTest(hooks); -// Replace this with your real tests. -test('it exists', function(assert) { - let service = this.subject(); - assert.ok(service); + // Replace this with your real tests. + test('it exists', function(assert) { + let service = this.owner.lookup('service:resize-detector'); + assert.ok(service); + }); });