test: carousel core change/destroy edge cases
This commit is contained in:
@@ -55,3 +55,33 @@ test('next/prev clamp to range and scroll to target offset', () => {
|
||||
c.next();
|
||||
expect(track.scrollTo).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test('change fires with new index when a slide intersects', () => {
|
||||
const c = createCarousel(track);
|
||||
const seen: number[] = [];
|
||||
c.on('change', (i) => seen.push(i));
|
||||
(IOShim.last as IOShim).emit(2); // user swiped to slide 2
|
||||
expect(seen).toEqual([2]);
|
||||
expect(c.index).toBe(2);
|
||||
});
|
||||
|
||||
test('change does not re-fire for the same index', () => {
|
||||
const c = createCarousel(track);
|
||||
const seen: number[] = [];
|
||||
c.on('change', (i) => seen.push(i));
|
||||
(IOShim.last as IOShim).emit(1);
|
||||
(IOShim.last as IOShim).emit(1);
|
||||
expect(seen).toEqual([1]);
|
||||
});
|
||||
|
||||
test('unsubscribe stops delivery; destroy disconnects observer', () => {
|
||||
const c = createCarousel(track);
|
||||
const seen: number[] = [];
|
||||
const off = c.on('change', (i) => seen.push(i));
|
||||
off();
|
||||
(IOShim.last as IOShim).emit(2);
|
||||
expect(seen).toEqual([]);
|
||||
const spy = vi.spyOn(IOShim.last as IOShim, 'disconnect');
|
||||
c.destroy();
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user