|
1 | 1 | import { module, test } from 'qunit';
|
2 | 2 | import { setupRenderingTest } from 'ember-qunit';
|
3 |
| -import { render } from '@ember/test-helpers'; |
| 3 | +import { render, setupOnerror } from '@ember/test-helpers'; |
4 | 4 | import hbs from 'htmlbars-inline-precompile';
|
5 | 5 |
|
6 | 6 | module('Integration | Modifier | will-destroy', function (hooks) {
|
@@ -43,4 +43,57 @@ module('Integration | Modifier | will-destroy', function (hooks) {
|
43 | 43 | // trigger destroy
|
44 | 44 | this.set('show', false);
|
45 | 45 | });
|
| 46 | + |
| 47 | + test('provides a useful error on install', async function (assert) { |
| 48 | + assert.expect(1); |
| 49 | + |
| 50 | + // Setup error capturing |
| 51 | + setupOnerror(function (err) { |
| 52 | + assert.equal( |
| 53 | + err.toString(), |
| 54 | + `TypeError: did-destroy expected a function, instead received "undefined"` |
| 55 | + ); |
| 56 | + }); |
| 57 | + |
| 58 | + await render(hbs` |
| 59 | + <div {{will-destroy this.nonExistentMethod}}></div> |
| 60 | + `); |
| 61 | + |
| 62 | + // Prevent double error on test teardown |
| 63 | + this.set('nonExistentMethod', () => {}); |
| 64 | + |
| 65 | + // Reset error capturing |
| 66 | + setupOnerror(); |
| 67 | + }); |
| 68 | + |
| 69 | + test('provides a useful error on destroy', async function (assert) { |
| 70 | + assert.expect(1); |
| 71 | + |
| 72 | + // Start with a valid function so that install works |
| 73 | + this.set('nonExistentMethod', () => {}); |
| 74 | + |
| 75 | + // Setup error capturing |
| 76 | + setupOnerror(function (err) { |
| 77 | + assert.equal( |
| 78 | + err.toString(), |
| 79 | + `TypeError: did-destroy expected a function, instead received "undefined"` |
| 80 | + ); |
| 81 | + }); |
| 82 | + |
| 83 | + this.set('show', true); |
| 84 | + await render(hbs` |
| 85 | + {{#if this.show}} |
| 86 | + <div {{will-destroy this.nonExistentMethod}}></div> |
| 87 | + {{/if}} |
| 88 | + `); |
| 89 | + |
| 90 | + // Remove the function to trigger an error on destroy |
| 91 | + this.setProperties({ |
| 92 | + nonExistentMethod: undefined, |
| 93 | + show: false, |
| 94 | + }); |
| 95 | + |
| 96 | + // Reset error capturing |
| 97 | + setupOnerror(); |
| 98 | + }); |
46 | 99 | });
|
0 commit comments