Skip to content

Commit

Permalink
Add a test that dedupeTracked works with EmberObject
Browse files Browse the repository at this point in the history
  • Loading branch information
boris-petrov committed Mar 17, 2022
1 parent ed33359 commit 96b9288
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/unit/dedupe-tracked-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import EmberObject from '@ember/object';
import { module, test } from 'qunit';
import { dedupeTracked, cached } from 'tracked-toolbox';

Expand Down Expand Up @@ -142,4 +143,35 @@ module('Unit | Utils | @dedupeTracked', () => {
'getter is called again after updating to a different value'
);
});

test('it works with an EmberObject', (assert) => {
let count = 0;

class Person extends EmberObject {
@dedupeTracked _name;

@cached
get name() {
count++;

return this._name;
}
}

const person = Person.create({ _name: 'Zoey' });

assert.strictEqual(person._name, 'Zoey', '_name should be initialized correctly');
assert.strictEqual(person.name, 'Zoey', 'name should be initialized correctly');
assert.strictEqual(count, 1, 'getter is called the first time');

person._name = 'Zoey';

assert.strictEqual(person.name, 'Zoey', 'name is unchanged');
assert.strictEqual(count, 1, 'getter is not called again after updating to the same value');

person._name = 'Tomster';

assert.strictEqual(person.name, 'Tomster', 'name is correct');
assert.strictEqual(count, 2, 'getter is called again after updating to a different value');
});
});

0 comments on commit 96b9288

Please sign in to comment.