Skip to content

Commit

Permalink
nonsensical tests
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky committed Nov 4, 2022
1 parent 8fcc089 commit 03c4cbb
Showing 1 changed file with 39 additions and 23 deletions.
62 changes: 39 additions & 23 deletions packages/browser/src/core/events/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,6 @@ describe('Event Factory', () => {
factory = new EventFactory(user)
})

describe('context', () => {
it('should do something with anonymousId', () => {
const [context, overrides] = factory['context']({
type: 'alias',
options: {
context: { anonymousId: 'ABC-123-XYZ' },
},
})
expect(overrides).toEqual({})
expect(context).toEqual({ anonymousId: 'ABC-123-XYZ' })
})
it('anonId on the base should override anonId on the context', () => {
const [context, overrides] = factory['context']({
type: 'alias',
options: {
anonymousId: 'DEF-567-ABC',
context: { anonymousId: 'ABC-123-XYZ' },
},
})
expect(overrides).toEqual({})
expect(context).toEqual({ anonymousId: 'DEF-567-ABC' })
})
})
describe('alias', () => {
test('creates alias events', () => {
const alias = factory.alias('netto', 'netto farah')
Expand Down Expand Up @@ -345,6 +322,45 @@ describe('Event Factory', () => {
innerProp: '👻',
})
})

describe('anonymousId', () => {
test('accepts an anonymousId', () => {
const track = factory.track('Order Completed', shoes, {
anonymousId: 'foo',
})
expect(track.anonymousId).toBe('foo')
expect(track.context?.anonymousId).toBe('foo')
})

test('custom passed anonymousId should set global user instance', () => {
const id = Math.random().toString()
factory.track('Order Completed', shoes, {
anonymousId: id,
})
expect(user.anonymousId()).toBe(id)
})

test('if two different anonymousIds are passed, should use one on the event', () => {
const track = factory.track('Order Completed', shoes, {
anonymousId: 'bar',
context: {
anonymousId: 'foo',
},
})
expect(track.context?.anonymousId).toBe('bar')
expect(track.anonymousId).toBe('bar')
})

test('should set an anonymousId passed from the context on the event', () => {
const track = factory.track('Order Completed', shoes, {
context: {
anonymousId: 'foo',
},
})
expect(track.context?.anonymousId).toBe('foo')
expect(track.anonymousId).toBe('foo')
})
})
})

describe('normalize', function () {
Expand Down

0 comments on commit 03c4cbb

Please sign in to comment.