Skip to content

Commit cf434e3

Browse files
author
Robert Jackson
committed
Avoid using @tracked in tests when it isn't available
1 parent 94b3132 commit cf434e3

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

tests/integration/modifiers/did-update-test.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { setupRenderingTest } from 'ember-qunit';
44
import { render, settled } from '@ember/test-helpers';
55
import hbs from 'htmlbars-inline-precompile';
66

7+
import { macroCondition, dependencySatisfies} from '@embroider/macros';
8+
79
module('Integration | Modifier | did-update', function (hooks) {
810
setupRenderingTest(hooks);
911

@@ -26,27 +28,31 @@ module('Integration | Modifier | did-update', function (hooks) {
2628
this.set('boundValue', 'update');
2729
});
2830

29-
test('it consumes tracked properties without re-invoking', async function (assert) {
30-
assert.expect(1);
31+
// only run the next test where @tracked is present
32+
if (macroCondition(dependencySatisfies('ember-source', '>= 3.12.0'))) {
33+
test('it consumes tracked properties without re-invoking', async function (assert) {
3134

32-
class Context {
33-
@tracked boundValue = 'initial';
34-
@tracked secondaryValue = 'initial';
35-
}
35+
assert.expect(1);
3636

37-
this.context = new Context();
37+
class Context {
38+
@tracked boundValue = 'initial';
39+
@tracked secondaryValue = 'initial';
40+
}
3841

39-
this.someMethod = () => {
40-
// This assertion works as an assurance that we render before `secondaryValue` changes,
41-
// and consumes its tag to ensure reading tracked properties won't re-trigger the modifier
42-
assert.equal(this.context.secondaryValue, 'initial');
43-
};
42+
this.context = new Context();
4443

45-
await render(hbs`<div {{did-update this.someMethod this.context.boundValue}}></div>`);
44+
this.someMethod = () => {
45+
// This assertion works as an assurance that we render before `secondaryValue` changes,
46+
// and consumes its tag to ensure reading tracked properties won't re-trigger the modifier
47+
assert.equal(this.context.secondaryValue, 'initial');
48+
};
4649

47-
this.context.boundValue = 'update';
48-
await settled();
49-
this.context.secondaryValue = 'update';
50-
await settled();
51-
});
50+
await render(hbs`<div {{did-update this.someMethod this.context.boundValue}}></div>`);
51+
52+
this.context.boundValue = 'update';
53+
await settled();
54+
this.context.secondaryValue = 'update';
55+
await settled();
56+
});
57+
}
5258
});

0 commit comments

Comments
 (0)