|
|
|
@ -2,6 +2,9 @@ import { Field, FieldType } from '../types'; |
|
|
|
|
|
|
|
|
|
import { ArrayVector } from './ArrayVector'; |
|
|
|
|
|
|
|
|
|
// There's lots of @ts-expect-error here, because we actually expect it to be a typescript error
|
|
|
|
|
// to further encourge developers not to use ArrayVector
|
|
|
|
|
|
|
|
|
|
describe('ArrayVector', () => { |
|
|
|
|
beforeEach(() => { |
|
|
|
|
jest.spyOn(console, 'warn').mockImplementation(); |
|
|
|
@ -9,12 +12,14 @@ describe('ArrayVector', () => { |
|
|
|
|
|
|
|
|
|
it('should init 150k with 65k Array.push() chonking', () => { |
|
|
|
|
const arr = Array.from({ length: 150e3 }, (v, i) => i); |
|
|
|
|
/// @ts-expect-error
|
|
|
|
|
const av = new ArrayVector(arr); |
|
|
|
|
|
|
|
|
|
expect(av.toArray()).toEqual(arr); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should support add and push', () => { |
|
|
|
|
/// @ts-expect-error
|
|
|
|
|
const av = new ArrayVector<number>(); |
|
|
|
|
av.add(1); |
|
|
|
|
av.push(2); |
|
|
|
@ -28,17 +33,26 @@ describe('ArrayVector', () => { |
|
|
|
|
name: 'test', |
|
|
|
|
config: {}, |
|
|
|
|
type: FieldType.number, |
|
|
|
|
/// @ts-expect-error
|
|
|
|
|
values: new ArrayVector(), // this defaults to `new ArrayVector<any>()`
|
|
|
|
|
}; |
|
|
|
|
expect(field).toBeDefined(); |
|
|
|
|
|
|
|
|
|
// Before collapsing Vector, ReadWriteVector, and MutableVector these all worked fine
|
|
|
|
|
|
|
|
|
|
/// @ts-expect-error
|
|
|
|
|
field.values = new ArrayVector(); |
|
|
|
|
/// @ts-expect-error
|
|
|
|
|
field.values = new ArrayVector(undefined); |
|
|
|
|
/// @ts-expect-error
|
|
|
|
|
field.values = new ArrayVector([1, 2, 3]); |
|
|
|
|
/// @ts-expect-error
|
|
|
|
|
field.values = new ArrayVector([]); |
|
|
|
|
/// @ts-expect-error
|
|
|
|
|
field.values = new ArrayVector([1, undefined]); |
|
|
|
|
/// @ts-expect-error
|
|
|
|
|
field.values = new ArrayVector([null]); |
|
|
|
|
/// @ts-expect-error
|
|
|
|
|
field.values = new ArrayVector(['a', 'b', 'c']); |
|
|
|
|
expect(field.values.length).toBe(3); |
|
|
|
|
}); |
|
|
|
|