Skip to content

Commit

Permalink
feat: support assertions on elements and arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1211 committed Feb 18, 2021
1 parent f5bd5f9 commit 402ef9f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/util/getElements.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export default async function getElements(selectorOrPromise, client) {
if (selectorOrPromise instanceof Promise) {
const resolved = await selectorOrPromise
const selector = selectorOrPromise.selector || String(resolved)
if (typeof resolved === 'string') selectorOrPromise = resolved
export default async function getElements(obj, client) {
if (obj instanceof Promise) {
const resolved = await obj
const selector = obj.selector || String(resolved)
if (typeof resolved === 'string') obj = resolved
else if (Array.isArray(resolved)) return [resolved, selector]
else if (resolved) return [[resolved], selector]
}

return typeof selectorOrPromise === 'string'
? [await client.$$(selectorOrPromise), selectorOrPromise]
: [[], selectorOrPromise]
if (Array.isArray(obj)) return [obj, obj.join(', ')]
if (typeof obj === 'string') return [await client.$$(obj), obj]
if (obj) return [[obj], String(obj)]
return [[], String(obj)]
}
14 changes: 13 additions & 1 deletion test/assertions/booleanAssertionTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,22 @@ export const booleanAssertionTest = ({
fakeElement1[`is${upperFirst(method)}`].resolves(true)
await expect('.some-selector').to.be[method]()
})
it(`resolves when element is ${expectation} -- via promise`, async function() {
it(`resolves when element is ${expectation} -- via promise resolving to array`, async function() {
fakeElement1[`is${upperFirst(method)}`].resolves(true)
await expect(Promise.resolve([fakeElement1])).to.be[method]()
})
it(`resolves when element is ${expectation} -- via promise resolving to element`, async function() {
fakeElement1[`is${upperFirst(method)}`].resolves(true)
await expect(Promise.resolve(fakeElement1)).to.be[method]()
})
it(`resolves when element is ${expectation} -- via array`, async function() {
fakeElement1[`is${upperFirst(method)}`].resolves(true)
await expect([fakeElement1]).to.be[method]()
})
it(`resolves when element is ${expectation} -- via element`, async function() {
fakeElement1[`is${upperFirst(method)}`].resolves(true)
await expect(fakeElement1).to.be[method]()
})
it(`rejects when element is not ${expectation}`, async function() {
await expect('.some-selector')
.to.be[method]()
Expand Down

0 comments on commit 402ef9f

Please sign in to comment.