|
1 | 1 | import { BidiModule, Dir } from '@angular/cdk/bidi';
|
2 | 2 | import { LEFT_ARROW, RIGHT_ARROW } from '@angular/cdk/keycodes';
|
3 | 3 | import { Component, DebugElement, ViewChild } from '@angular/core';
|
4 |
| -import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; |
| 4 | +import { ComponentFixture, discardPeriodicTasks, fakeAsync, TestBed, tick } from '@angular/core/testing'; |
5 | 5 | import { By } from '@angular/platform-browser';
|
6 | 6 |
|
| 7 | +import { NzResizeObserver } from 'ng-zorro-antd/cdk/resize-observer'; |
7 | 8 | import { dispatchKeyboardEvent, dispatchMouseEvent } from 'ng-zorro-antd/core/testing';
|
8 | 9 |
|
9 | 10 | import { NzCarouselContentDirective } from './carousel-content.directive';
|
@@ -76,6 +77,28 @@ describe('carousel', () => {
|
76 | 77 | ).toBe('A');
|
77 | 78 | });
|
78 | 79 |
|
| 80 | + it('should call layout on component resize', fakeAsync(() => { |
| 81 | + testComponent.nzCarouselComponent.ngOnInit(); |
| 82 | + const spy = spyOn(testComponent.nzCarouselComponent, 'layout'); |
| 83 | + window.dispatchEvent(new Event('resize')); |
| 84 | + tick(500); |
| 85 | + |
| 86 | + (testComponent.nzCarouselComponent['nzResizeObserver'] as NzResizeObserver) |
| 87 | + .observe(testComponent.nzCarouselComponent.el) |
| 88 | + .subscribe(() => { |
| 89 | + expect(spy).toHaveBeenCalled(); |
| 90 | + }); |
| 91 | + })); |
| 92 | + |
| 93 | + it('should call layout on component resize', fakeAsync(() => { |
| 94 | + const spyOnResize = spyOn(testComponent.nzCarouselComponent, 'layout'); |
| 95 | + window.dispatchEvent(new Event('resize')); |
| 96 | + tick(500); |
| 97 | + |
| 98 | + expect(spyOnResize).toHaveBeenCalled(); |
| 99 | + discardPeriodicTasks(); |
| 100 | + })); |
| 101 | + |
79 | 102 | it('should click content change', () => {
|
80 | 103 | expect(carouselContents[0].nativeElement.classList).toContain('slick-active');
|
81 | 104 | carouselWrapper.nativeElement.querySelector('.slick-dots').lastElementChild.click();
|
|
0 commit comments