Skip to content
This repository was archived by the owner on Jan 3, 2019. It is now read-only.

Commit 03fbb4a

Browse files
authored
feat(base): add guard to method nth of component (#181)
1 parent 5489f6e commit 03fbb4a

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

@pageobject/base/src/Component.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function describeExistingVariants<TComponent extends TestComponent>(
7979

8080
return [
8181
new Descriptor(
82-
component.nth(position + 1).nth(position),
82+
component.nth(position),
8383
`.nth(${position})`,
8484
parentDescriptor,
8585
position
@@ -213,6 +213,12 @@ function describeTests<TComponent extends TestComponent>(
213213
'Position must be one-based'
214214
);
215215
});
216+
217+
it('should throw a state error', () => {
218+
expect(() => descriptor.component.nth(1).nth(2)).toThrow(
219+
'Position is already set'
220+
);
221+
});
216222
});
217223

218224
describe('getElementCount() => Effect', () => {

@pageobject/base/src/Component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ export class Component<TElement> implements Describable {
6868
throw new Error('Position must be one-based');
6969
}
7070

71+
if (this._locator.position) {
72+
throw new Error('Position is already set');
73+
}
74+
7175
return this._ownFactory.create(this._adapter, {...this._locator, position});
7276
}
7377

docs/api/base/classes/component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ <h3><span class="tsd-flag ts-flagProtected">Protected</span> find<wbr>Element</h
11311131
<li class="tsd-description">
11321132
<aside class="tsd-sources">
11331133
<ul>
1134-
<li>Defined in <a href="https://github.com/clebert/pageobject/blob/master/@pageobject/base/src/Component.ts#L92">Component.ts:92</a></li>
1134+
<li>Defined in <a href="https://github.com/clebert/pageobject/blob/master/@pageobject/base/src/Component.ts#L96">Component.ts:96</a></li>
11351135
</ul>
11361136
</aside>
11371137
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">TElement</span><span class="tsd-signature-symbol">&gt;</span></h4>
@@ -1148,7 +1148,7 @@ <h3><span class="tsd-flag ts-flagProtected">Protected</span> find<wbr>Elements</
11481148
<li class="tsd-description">
11491149
<aside class="tsd-sources">
11501150
<ul>
1151-
<li>Defined in <a href="https://github.com/clebert/pageobject/blob/master/@pageobject/base/src/Component.ts#L106">Component.ts:106</a></li>
1151+
<li>Defined in <a href="https://github.com/clebert/pageobject/blob/master/@pageobject/base/src/Component.ts#L110">Component.ts:110</a></li>
11521152
</ul>
11531153
</aside>
11541154
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">TElement</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">&gt;</span></h4>
@@ -1165,7 +1165,7 @@ <h3>get<wbr>Element<wbr>Count</h3>
11651165
<li class="tsd-description">
11661166
<aside class="tsd-sources">
11671167
<ul>
1168-
<li>Defined in <a href="https://github.com/clebert/pageobject/blob/master/@pageobject/base/src/Component.ts#L86">Component.ts:86</a></li>
1168+
<li>Defined in <a href="https://github.com/clebert/pageobject/blob/master/@pageobject/base/src/Component.ts#L90">Component.ts:90</a></li>
11691169
</ul>
11701170
</aside>
11711171
<h4 class="tsd-returns-title">Returns <a href="../interfaces/effect.html" class="tsd-signature-type">Effect</a><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">&gt;</span></h4>
@@ -1234,7 +1234,7 @@ <h3>where</h3>
12341234
<li class="tsd-description">
12351235
<aside class="tsd-sources">
12361236
<ul>
1237-
<li>Defined in <a href="https://github.com/clebert/pageobject/blob/master/@pageobject/base/src/Component.ts#L74">Component.ts:74</a></li>
1237+
<li>Defined in <a href="https://github.com/clebert/pageobject/blob/master/@pageobject/base/src/Component.ts#L78">Component.ts:78</a></li>
12381238
</ul>
12391239
</aside>
12401240
<h4 class="tsd-type-parameters-title">Type parameters</h4>

0 commit comments

Comments
 (0)