|
| 1 | +import { module, test } from 'qunit'; |
| 2 | +import { setupRenderingTest } from 'ember-qunit'; |
| 3 | +import { render } from '@ember/test-helpers'; |
| 4 | +import hbs from 'htmlbars-inline-precompile'; |
| 5 | + |
| 6 | +module('Integration | Modifier | did-insert', function(hooks) { |
| 7 | + setupRenderingTest(hooks); |
| 8 | + |
| 9 | + test('it basically works', async function(assert) { |
| 10 | + assert.expect(2); |
| 11 | + |
| 12 | + this.someMethod = element => { |
| 13 | + assert.equal(element.tagName, 'DIV', 'correct element tagName'); |
| 14 | + assert.dom(element).hasAttribute('data-foo', 'some-thing'); |
| 15 | + }; |
| 16 | + await render(hbs`<div data-foo="some-thing" {{did-insert this.someMethod}}></div>`); |
| 17 | + }); |
| 18 | + |
| 19 | + test('it can accept arguments', async function(assert) { |
| 20 | + assert.expect(4); |
| 21 | + |
| 22 | + this.someMethod = (element, positional, named) => { |
| 23 | + assert.equal(element.tagName, 'DIV', 'correct element tagName'); |
| 24 | + assert.dom(element).hasAttribute('data-foo', 'some-thing'); |
| 25 | + |
| 26 | + assert.deepEqual(named, { some: 'hash-value' }, 'named args match'); |
| 27 | + assert.deepEqual(positional, ['some-positional-value'], 'positional args match'); |
| 28 | + }; |
| 29 | + |
| 30 | + await render( |
| 31 | + hbs`<div data-foo="some-thing" {{did-insert this.someMethod "some-positional-value" some="hash-value"}}></div>` |
| 32 | + ); |
| 33 | + }); |
| 34 | + |
| 35 | + test('it is not invoked again when arguments change', async function(assert) { |
| 36 | + assert.expect(4); |
| 37 | + |
| 38 | + this.someMethod = (element, positional, named) => { |
| 39 | + assert.equal(element.tagName, 'DIV', 'correct element tagName'); |
| 40 | + assert.dom(element).hasAttribute('data-foo', 'some-thing'); |
| 41 | + |
| 42 | + assert.deepEqual(named, {}, 'named args match'); |
| 43 | + assert.deepEqual(positional, ['initial'], 'positional args match'); |
| 44 | + }; |
| 45 | + |
| 46 | + this.set('firstArg', 'initial'); |
| 47 | + await render( |
| 48 | + hbs`<div data-foo="some-thing" {{did-insert this.someMethod this.firstArg}}></div>` |
| 49 | + ); |
| 50 | + this.set('firstArg', 'updated'); |
| 51 | + }); |
| 52 | +}); |
0 commit comments