Skip to content

Commit c583cff

Browse files
committed
fix: conditional tests
1 parent 30da677 commit c583cff

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

ember-engines-router-service/src/services/engine-router-service.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import { namespaceEngineRouteName } from '../utils/namespace-engine-route-name';
1010
import { getRootOwner } from '../utils/root-owner';
1111
import { resemblesURL } from '../utils/resembles-url';
1212

13+
const warningMessage =
14+
'Refresh method is not available in ember-source below v4.1';
15+
1316
export default class EngineRouterService extends Service.extend(Evented) {
1417
constructor(...args) {
1518
super(...args);
@@ -77,7 +80,7 @@ export default class EngineRouterService extends Service.extend(Evented) {
7780
...args
7881
);
7982
} else {
80-
assert('Refresh method is not available in ember-source below v4.1');
83+
assert(warningMessage);
8184
}
8285
}
8386

@@ -88,7 +91,7 @@ export default class EngineRouterService extends Service.extend(Evented) {
8891
...args
8992
);
9093
} else {
91-
assert('Refresh method is not available in ember-source below v4.1');
94+
assert(warningMessage);
9295
}
9396
}
9497

test-app/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@ember/optional-features": "^2.0.0",
3838
"@ember/string": "^3.1.1",
3939
"@ember/test-helpers": "^2.9.3",
40+
"@embroider/macros": "^1.13.2",
4041
"@embroider/test-setup": "^2.0.2",
4142
"@glimmer/component": "^1.1.2",
4243
"@glimmer/tracking": "^1.1.2",

test-app/tests/acceptance/routeable-engine-demo-refresh-test.js

+23-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
11
import { module, test } from 'qunit';
22
import { setupApplicationTest } from 'ember-qunit';
33
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';
48

59
module('Acceptance | Engine Router Service | Refresh Method', function (hooks) {
610
setupApplicationTest(hooks);
711

812
test('refresh without params triggers refresh with current route', async function (assert) {
13+
assert.expect(1);
914
await visit('/routable-engine-demo/ember-blog/new');
1015

1116
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+
}
1835
});
1936

2037
test('refresh with params triggers refresh on provided route', async function (assert) {

0 commit comments

Comments
 (0)