Skip to content

Commit

Permalink
fix: conditional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aklkv committed Nov 3, 2023
1 parent 30da677 commit c583cff
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { namespaceEngineRouteName } from '../utils/namespace-engine-route-name';
import { getRootOwner } from '../utils/root-owner';
import { resemblesURL } from '../utils/resembles-url';

const warningMessage =
'Refresh method is not available in ember-source below v4.1';

export default class EngineRouterService extends Service.extend(Evented) {
constructor(...args) {
super(...args);
Expand Down Expand Up @@ -77,7 +80,7 @@ export default class EngineRouterService extends Service.extend(Evented) {
...args
);
} else {
assert('Refresh method is not available in ember-source below v4.1');
assert(warningMessage);
}
}

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

Expand Down
1 change: 1 addition & 0 deletions test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@ember/optional-features": "^2.0.0",
"@ember/string": "^3.1.1",
"@ember/test-helpers": "^2.9.3",
"@embroider/macros": "^1.13.2",
"@embroider/test-setup": "^2.0.2",
"@glimmer/component": "^1.1.2",
"@glimmer/tracking": "^1.1.2",
Expand Down
29 changes: 23 additions & 6 deletions test-app/tests/acceptance/routeable-engine-demo-refresh-test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { visit, find, click } from '@ember/test-helpers';
import { macroCondition, dependencySatisfies } from '@embroider/macros';

const warningMessage =
'Refresh method is not available in ember-source below v4.1';

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

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

let counter = await find('.route-refresh-counter').textContent;
await click('.refresh');

counter = parseInt(counter, 10);
counter = ++counter;
counter = counter.toString();
assert.dom('.route-refresh-counter').hasText(counter);
if (macroCondition(dependencySatisfies('ember-source', '>= 4.1.0'))) {
await click('.refresh');

counter = parseInt(counter, 10);
counter = ++counter;
counter = counter.toString();
assert.dom('.route-refresh-counter').hasText(counter);
} else {
// eslint-disable-next-line qunit/no-conditional-assertions
assert.throws(
async () => {
await click('.refresh');
},
(error) => {
assert.strictEqual(error.message, warningMessage);
}
);
}
});

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

0 comments on commit c583cff

Please sign in to comment.