|
1 | | -import { Analytics } from '@/core/analytics' |
2 | | -import { Context } from '@/core/context' |
3 | | -import { AnalyticsBrowser } from '@/browser' |
4 | | -import { assertNotAny, assertIs } from '@/test-helpers/type-assertions' |
5 | | -import { Group, User } from '../../../core/user' |
| 1 | +import { AnalyticsBrowser, Analytics, Context, User, Group } from '../../..' |
| 2 | +import { assertNotAny, assertIs } from '../../../test-helpers/type-assertions' |
6 | 3 |
|
7 | 4 | /** |
8 | 5 | * These are general typescript definition tests; |
@@ -77,23 +74,23 @@ export default { |
77 | 74 | 'Identify should work with spread objects ': () => { |
78 | 75 | const user = { |
79 | 76 | name: 'john', |
80 | | - id: 12345, |
| 77 | + id: 'abc123', |
81 | 78 | } |
82 | 79 | const { id, ...traits } = user |
83 | 80 | void AnalyticsBrowser.load({ writeKey: 'foo' }).identify('foo', traits) |
84 | 81 | }, |
85 | 82 | 'Track should work with spread objects': () => { |
86 | 83 | const user = { |
87 | 84 | name: 'john', |
88 | | - id: 12345, |
| 85 | + id: 'abc123', |
89 | 86 | } |
90 | 87 | const { id, ...traits } = user |
91 | 88 | void AnalyticsBrowser.load({ writeKey: 'foo' }).track('foo', traits) |
92 | 89 | }, |
93 | 90 | 'Identify should work with generic objects ': () => { |
94 | 91 | const user = { |
95 | 92 | name: 'john', |
96 | | - id: 12345, |
| 93 | + id: 'abc123', |
97 | 94 | } |
98 | 95 | void AnalyticsBrowser.load({ writeKey: 'foo' }).identify('foo', user) |
99 | 96 | }, |
@@ -122,4 +119,12 @@ export default { |
122 | 119 | assertNotAny(analytics) |
123 | 120 | assertIs<AnalyticsBrowser>(analytics) |
124 | 121 | }, |
| 122 | + 'Should error if there is a type conflict in Traits': () => { |
| 123 | + const analytics = new AnalyticsBrowser().load({ writeKey: 'foo' }) |
| 124 | + assertNotAny(analytics) |
| 125 | + assertIs<AnalyticsBrowser>(analytics) |
| 126 | + |
| 127 | + // @ts-expect-error - id should be a string |
| 128 | + void analytics.identify('foo', { id: 123 }) |
| 129 | + }, |
125 | 130 | } |
0 commit comments