Skip to content

Commit

Permalink
test(content): fix unit test by using new elementRef api
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Mar 14, 2017
1 parent 7a9f88f commit f9f9a1b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/components/content/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ export class Content extends Ion implements OnDestroy, OnInit {

const scrollEle = this.getScrollElement();
if (!scrollEle) {
assert(false, 'this._scrollEle should be valid');
assert(false, 'this.getScrollElement() should be valid');
return;
}

Expand Down
7 changes: 4 additions & 3 deletions src/components/img/test/img.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ElementRef, Renderer } from '@angular/core';
import { Content } from '../../content/content';
import { DomController } from '../../../platform/dom-controller';
import { Img } from '../img';
import { mockConfig, mockDomController, mockElementRef, mockPlatform, mockRenderer, mockZone } from '../../../util/mock-providers';
import { mockConfig, mockDomController, mockElementRef, mockElementRefEle, mockPlatform, mockRenderer, mockZone } from '../../../util/mock-providers';
import { Platform } from '../../../platform/platform';


Expand Down Expand Up @@ -60,8 +60,9 @@ describe('Img', () => {
contentElementRef = mockElementRef();
dom = mockDomController();
content = new Content(mockConfig(), mockPlatform(), dom, contentElementRef, mockRenderer(), null, null, mockZone(), null, null);
content._scrollEle = document.createElement('div');
content._scrollEle.className = 'scroll-content';
let ele = document.createElement('div');
ele.className = 'scroll-content';
content._scrollContent = mockElementRefEle(ele);

elementRef = mockElementRef();
renderer = mockRenderer();
Expand Down
7 changes: 4 additions & 3 deletions src/components/infinite-scroll/test/infinite-scroll.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Content, ScrollEvent } from '../../content/content';
import { DomController } from '../../../platform/dom-controller';
import { InfiniteScroll } from '../infinite-scroll';
import { mockConfig, mockDomController, mockElementRef, mockPlatform, mockRenderer, mockZone } from '../../../util/mock-providers';
import { mockConfig, mockDomController, mockElementRef, mockElementRefEle, mockPlatform, mockRenderer, mockZone } from '../../../util/mock-providers';


describe('Infinite Scroll', () => {
Expand Down Expand Up @@ -104,8 +104,9 @@ describe('Infinite Scroll', () => {
contentElementRef = mockElementRef();
dom = mockDomController();
content = new Content(config, mockPlatform(), dom, contentElementRef, mockRenderer(), null, null, mockZone(), null, null);
content._scrollEle = document.createElement('div');
content._scrollEle.className = 'scroll-content';
let ele = document.createElement('div');
ele.className = 'scroll-content';
content._scrollContent = mockElementRefEle(ele);

infiniteElementRef = mockElementRef();

Expand Down
11 changes: 4 additions & 7 deletions src/components/refresher/test/refresher.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Refresher } from '../refresher';
import { Content } from '../../content/content';
import { GestureController } from '../../../gestures/gesture-controller';
import { mockConfig, mockDomController, mockElementRef, mockPlatform, mockRenderer, mockZone } from '../../../util/mock-providers';
import { mockConfig, mockDomController, mockElementRef, mockElementRefEle, mockPlatform, mockRenderer, mockZone } from '../../../util/mock-providers';


describe('Refresher', () => {
Expand Down Expand Up @@ -234,8 +234,9 @@ describe('Refresher', () => {
contentElementRef = mockElementRef();
dom = mockDomController();
content = new Content(mockConfig(), mockPlatform(), dom, contentElementRef, mockRenderer(), null, null, mockZone(), null, null);
content._scrollEle = document.createElement('div');
content._scrollEle.className = 'scroll-content';
let ele = document.createElement('div');
ele.className = 'scroll-content';
content._scrollContent = mockElementRefEle(ele);

let gestureController = new GestureController(null);

Expand Down Expand Up @@ -270,8 +271,4 @@ describe('Refresher', () => {
};
}

// function getScrollElementStyles() {
// return content._scrollEle.style;
// }

});
11 changes: 9 additions & 2 deletions src/util/mock-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ export function mockChangeDetectorRef(): ChangeDetectorRef {
}

export class MockElementRef implements ElementRef {
nativeElement: any = new MockElement();
nativeElement: any;
constructor(ele: any) {
this.nativeElement = ele;
}
}

export class MockElement {
Expand Down Expand Up @@ -299,7 +302,11 @@ export class ClassList {
}

export function mockElementRef(): ElementRef {
return new MockElementRef();
return new MockElementRef(new MockElement());
}

export function mockElementRefEle(ele: any): ElementRef {
return new MockElementRef(ele);
}

export class MockRenderer {
Expand Down

0 comments on commit f9f9a1b

Please sign in to comment.