Skip to content

Commit

Permalink
Add test with key path on embedded object.
Browse files Browse the repository at this point in the history
  • Loading branch information
elle-j committed Jul 10, 2024
1 parent d7a9573 commit 3cd14bf
Showing 1 changed file with 58 additions and 2 deletions.
60 changes: 58 additions & 2 deletions integration-tests/tests/src/tests/observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,8 +795,7 @@ describe("Observable", () => {
]);
});

// TODO: Add link to issue with collection listener not being fired on updates to embedded object.
it.skip("calls listener when embedded object is updated", async function (this: RealmObjectContext<Person>) {
it("calls listener when embedded object is updated", async function (this: RealmObjectContext<Person>) {
const collection = this.realm.objects("Person");

await expectCollectionNotifications(collection, undefined, [
Expand Down Expand Up @@ -994,6 +993,63 @@ describe("Observable", () => {
);
});

it("fires on relevant changes to an embedded object", async function (this: RealmObjectContext<Person>) {
const collection = this.realm.objects("Person");

await expectCollectionNotifications(
collection,
["embeddedAddress"],
[
EMPTY_COLLECTION_CHANGESET,
() => {
this.realm.write(() => {
this.object.embeddedAddress = { street: "1633 Broadway", city: "New York" };
});
expect(this.object.embeddedAddress).deep.equals({ street: "1633 Broadway", city: "New York" });
},
{
deletions: [],
insertions: [],
newModifications: [0],
oldModifications: [0],
},
() => {
this.realm.write(() => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.object.embeddedAddress!.street = "88 Kearny Street";
});
expect(this.object.embeddedAddress?.street).equals("88 Kearny Street");
},
{
deletions: [],
insertions: [],
newModifications: [0],
oldModifications: [0],
},
() => {
this.realm.write(() => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.object.embeddedAddress!.city = "San Francisco";
});
expect(this.object.embeddedAddress?.city).equals("San Francisco");
},
{
deletions: [],
insertions: [],
newModifications: [0],
oldModifications: [0],
},
// Perform a couple of changes that shouldn't trigger the listener.
() => {
this.realm.write(() => {
this.object.name = "New Name";
});
expect(this.object.name).equals("New Name");
},
],
);
});

it("fires on relevant changes to a wildcard", async function (this: RealmObjectContext<Person>) {
const collection = this.realm.objects<Person>("Person").filtered("name = $0 OR age = 42", "Alice");
await expectCollectionNotifications(
Expand Down

0 comments on commit 3cd14bf

Please sign in to comment.