Skip to content

Commit 402ef9f

Browse files
committed
feat: support assertions on elements and arrays
1 parent f5bd5f9 commit 402ef9f

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/util/getElements.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
export default async function getElements(selectorOrPromise, client) {
2-
if (selectorOrPromise instanceof Promise) {
3-
const resolved = await selectorOrPromise
4-
const selector = selectorOrPromise.selector || String(resolved)
5-
if (typeof resolved === 'string') selectorOrPromise = resolved
1+
export default async function getElements(obj, client) {
2+
if (obj instanceof Promise) {
3+
const resolved = await obj
4+
const selector = obj.selector || String(resolved)
5+
if (typeof resolved === 'string') obj = resolved
66
else if (Array.isArray(resolved)) return [resolved, selector]
77
else if (resolved) return [[resolved], selector]
88
}
9-
10-
return typeof selectorOrPromise === 'string'
11-
? [await client.$$(selectorOrPromise), selectorOrPromise]
12-
: [[], selectorOrPromise]
9+
if (Array.isArray(obj)) return [obj, obj.join(', ')]
10+
if (typeof obj === 'string') return [await client.$$(obj), obj]
11+
if (obj) return [[obj], String(obj)]
12+
return [[], String(obj)]
1313
}

test/assertions/booleanAssertionTest.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,22 @@ export const booleanAssertionTest = ({
3636
fakeElement1[`is${upperFirst(method)}`].resolves(true)
3737
await expect('.some-selector').to.be[method]()
3838
})
39-
it(`resolves when element is ${expectation} -- via promise`, async function() {
39+
it(`resolves when element is ${expectation} -- via promise resolving to array`, async function() {
40+
fakeElement1[`is${upperFirst(method)}`].resolves(true)
41+
await expect(Promise.resolve([fakeElement1])).to.be[method]()
42+
})
43+
it(`resolves when element is ${expectation} -- via promise resolving to element`, async function() {
4044
fakeElement1[`is${upperFirst(method)}`].resolves(true)
4145
await expect(Promise.resolve(fakeElement1)).to.be[method]()
4246
})
47+
it(`resolves when element is ${expectation} -- via array`, async function() {
48+
fakeElement1[`is${upperFirst(method)}`].resolves(true)
49+
await expect([fakeElement1]).to.be[method]()
50+
})
51+
it(`resolves when element is ${expectation} -- via element`, async function() {
52+
fakeElement1[`is${upperFirst(method)}`].resolves(true)
53+
await expect(fakeElement1).to.be[method]()
54+
})
4355
it(`rejects when element is not ${expectation}`, async function() {
4456
await expect('.some-selector')
4557
.to.be[method]()

0 commit comments

Comments
 (0)