Skip to content

Commit 88d8efd

Browse files
committed
fix: unit tests
1 parent a6a8848 commit 88d8efd

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

apps/nativescript-demo-ng/src/tests/spans.spec.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,25 +106,25 @@ describe('Spans', () => {
106106
expect(textBase.formattedText.spans.getItem(1).text).toBe('1');
107107
expect(textBase.formattedText.spans.getItem(2).text).toBe('2');
108108
});
109-
it('correctly adds dynamically', async () => {
109+
it('correctly adds dynamically when show is true', () => {
110110
const fixture = TestBed.createComponent(DynamicSpansComponent);
111-
const textBase = fixture.componentInstance.textBase.nativeElement;
111+
// default show = true
112112
fixture.detectChanges();
113+
const textBase = fixture.componentInstance.textBase.nativeElement;
113114
expect(textBase.formattedText.spans.length).toBe(3);
114115
expect(textBase.formattedText.spans.getItem(0).text).toBe('0');
115116
expect(textBase.formattedText.spans.getItem(1).text).toBe('1');
116117
expect(textBase.formattedText.spans.getItem(2).text).toBe('2');
118+
});
119+
120+
it('correctly adds dynamically when show is false', () => {
121+
const fixture = TestBed.createComponent(DynamicSpansComponent);
117122
fixture.componentInstance.show = false;
118123
fixture.detectChanges();
124+
const textBase = fixture.componentInstance.textBase.nativeElement;
119125
expect(textBase.formattedText.spans.length).toBe(2);
120126
expect(textBase.formattedText.spans.getItem(0).text).toBe('0');
121127
expect(textBase.formattedText.spans.getItem(1).text).toBe('2');
122-
fixture.componentInstance.show = true;
123-
fixture.detectChanges();
124-
expect(textBase.formattedText.spans.length).toBe(3);
125-
expect(textBase.formattedText.spans.getItem(0).text).toBe('0');
126-
expect(textBase.formattedText.spans.getItem(1).text).toBe('1');
127-
expect(textBase.formattedText.spans.getItem(2).text).toBe('2');
128128
});
129129

130130
it('correctly adds FormattedString', async () => {
@@ -137,25 +137,25 @@ describe('Spans', () => {
137137
expect(textBase.formattedText.spans.getItem(2).text).toBe('2');
138138
});
139139

140-
it('correctly adds FormattedString dynamically', async () => {
140+
it('correctly adds FormattedString dynamically when show is true', () => {
141141
const fixture = TestBed.createComponent(DynamicFormattedStringComponent);
142-
const textBase = fixture.componentInstance.textBase.nativeElement;
142+
// default show = true
143143
fixture.detectChanges();
144+
const textBase = fixture.componentInstance.textBase.nativeElement;
144145
expect(textBase.formattedText.spans.length).toBe(3);
145146
expect(textBase.formattedText.spans.getItem(0).text).toBe('0');
146147
expect(textBase.formattedText.spans.getItem(1).text).toBe('1');
147148
expect(textBase.formattedText.spans.getItem(2).text).toBe('2');
149+
});
150+
151+
it('correctly adds FormattedString dynamically when show is false', () => {
152+
const fixture = TestBed.createComponent(DynamicFormattedStringComponent);
148153
fixture.componentInstance.show = false;
149154
fixture.detectChanges();
155+
const textBase = fixture.componentInstance.textBase.nativeElement;
150156
expect(textBase.formattedText.spans.length).toBe(2);
151157
expect(textBase.formattedText.spans.getItem(0).text).toBe('0');
152158
expect(textBase.formattedText.spans.getItem(1).text).toBe('2');
153-
fixture.componentInstance.show = true;
154-
fixture.detectChanges();
155-
expect(textBase.formattedText.spans.length).toBe(3);
156-
expect(textBase.formattedText.spans.getItem(0).text).toBe('0');
157-
expect(textBase.formattedText.spans.getItem(1).text).toBe('1');
158-
expect(textBase.formattedText.spans.getItem(2).text).toBe('2');
159159
});
160160
});
161161
}

apps/nativescript-demo-ng/src/tests/textnode.spec.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,33 @@ describe('TextNode', () => {
3131
const textNode = new TextNode('foo');
3232
expect(textNode.text).toBe('foo');
3333
});
34-
it('should set text to Label', () => {
34+
it('should set initial text to Label', () => {
3535
const fixture = TestBed.createComponent(TextNodeComponent);
3636
fixture.detectChanges();
3737
const label = fixture.componentInstance.textElement.nativeElement;
3838
expect(label.text).toBe('textnode');
39+
});
40+
41+
it('should clear Label text for null value', () => {
42+
const fixture = TestBed.createComponent(TextNodeComponent);
3943
fixture.componentInstance.text = null;
4044
fixture.detectChanges();
45+
const label = fixture.componentInstance.textElement.nativeElement;
4146
expect(label.text).toBe('');
4247
});
4348

44-
it('should set text to Label with Spans', () => {
49+
it('should set initial text to Label with Spans', () => {
4550
const fixture = TestBed.createComponent(TextNodeSpansComponent);
4651
fixture.detectChanges();
4752
const label = fixture.componentInstance.textElement.nativeElement;
4853
expect(label.text).toBe('textnode');
54+
});
55+
56+
it('should clear Label text with Spans for null value', () => {
57+
const fixture = TestBed.createComponent(TextNodeSpansComponent);
4958
fixture.componentInstance.text = null;
5059
fixture.detectChanges();
60+
const label = fixture.componentInstance.textElement.nativeElement;
5161
expect(label.text).toBe('');
5262
});
5363
});

0 commit comments

Comments
 (0)