|
1 | 1 | import { module, test } from 'qunit';
|
2 | 2 | import { setupApplicationTest } from 'ember-qunit';
|
3 | 3 | import { visit, find, click } from '@ember/test-helpers';
|
| 4 | +import { macroCondition, dependencySatisfies } from '@embroider/macros'; |
| 5 | + |
| 6 | +const warningMessage = |
| 7 | + 'Refresh method is not available in ember-source below v4.1'; |
4 | 8 |
|
5 | 9 | module('Acceptance | Engine Router Service | Refresh Method', function (hooks) {
|
6 | 10 | setupApplicationTest(hooks);
|
7 | 11 |
|
8 | 12 | test('refresh without params triggers refresh with current route', async function (assert) {
|
| 13 | + assert.expect(1); |
9 | 14 | await visit('/routable-engine-demo/ember-blog/new');
|
10 | 15 |
|
11 | 16 | let counter = await find('.route-refresh-counter').textContent;
|
12 |
| - await click('.refresh'); |
13 |
| - |
14 |
| - counter = parseInt(counter, 10); |
15 |
| - counter = ++counter; |
16 |
| - counter = counter.toString(); |
17 |
| - assert.dom('.route-refresh-counter').hasText(counter); |
| 17 | + if (macroCondition(dependencySatisfies('ember-source', '>= 4.1.0'))) { |
| 18 | + await click('.refresh'); |
| 19 | + |
| 20 | + counter = parseInt(counter, 10); |
| 21 | + counter = ++counter; |
| 22 | + counter = counter.toString(); |
| 23 | + assert.dom('.route-refresh-counter').hasText(counter); |
| 24 | + } else { |
| 25 | + // eslint-disable-next-line qunit/no-conditional-assertions |
| 26 | + assert.throws( |
| 27 | + async () => { |
| 28 | + await click('.refresh'); |
| 29 | + }, |
| 30 | + (error) => { |
| 31 | + assert.strictEqual(error.message, warningMessage); |
| 32 | + } |
| 33 | + ); |
| 34 | + } |
18 | 35 | });
|
19 | 36 |
|
20 | 37 | test('refresh with params triggers refresh on provided route', async function (assert) {
|
|
0 commit comments