Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: confirm if logout clears traits (WIP) #230

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions test/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,31 @@ describe('Flagsmith.init', () => {
await flagsmith.identify(identityB)
expect(flagsmith.getTrait("a")).toEqual(undefined)
});
test('identifying with new identity after logout should not carry over previous traits for different identity', async () => {
// Given
const onChange = jest.fn()
const now = Date.now();
const identityA = `test_identity_a_${now}`
const identityB = `test_identity_b_${now}`
const { flagsmith, initConfig } = getFlagsmith({
onChange,
identity: identityA,
traits: { a: `example` },
cacheOptions: { skipAPI: true },
});
await flagsmith.init(initConfig);
expect(flagsmith.getTrait("a")).toEqual(`example`)

// Also force an identify call to ensure nothing else is being set
// as part of the identify call that perhaps doesn't get cleared
// by logout.
await flagsmith.identify(identityA)

// When
await flagsmith.logout()
await flagsmith.identify(identityB)

// Then
expect(flagsmith.getTrait("a")).toEqual(undefined)
});
});