Skip to content

Commit

Permalink
fix: make test for last seen by env not rely on array order (#5303)
Browse files Browse the repository at this point in the history
This test was flaky because it relied on the order of the array
returned. To make it less flaky, we now turn the array into an object
instead and compare that.
  • Loading branch information
thomasheartman authored Nov 8, 2023
1 parent ebf3102 commit 2695e38
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ test('response should include last seen at per environment correctly for a singl
.get(`/api/admin/projects/default/features/${featureName}`)
.expect(200);

expect(body.environments).toMatchObject([
const expected = [
{
name: 'default',
lastSeenAt: '2023-08-01T12:30:56.000Z',
Expand All @@ -201,5 +201,15 @@ test('response should include last seen at per environment correctly for a singl
name: 'production',
lastSeenAt: '2023-08-01T12:30:56.000Z',
},
]);
];

const toObject = (lastSeenAtEnvData) =>
Object.fromEntries(
lastSeenAtEnvData.map((env) => [
env.name,
{ lastSeenAt: env.lastSeenAt },
]),
);

expect(toObject(body.environments)).toMatchObject(toObject(expected));
});

0 comments on commit 2695e38

Please sign in to comment.