Skip to content

Commit 4f37bd8

Browse files
fix: support assymmetric matchers for property validations - fixes #1494
1 parent 3fdc1bd commit 4f37bd8

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/matchers/element/toHaveElementProperty.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async function condition(
2525
return { result: true, value: prop }
2626
}
2727

28-
if (!(value instanceof RegExp) && (typeof value !== 'string' || (typeof prop !== 'string' && !asString))) {
28+
if (!(value instanceof RegExp) && typeof prop !== 'string' && !asString) {
2929
return { result: prop === value, value: prop }
3030
}
3131

test/matchers/element/toHaveElementProperty.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ describe('toHaveElementProperty', () => {
3333
})
3434
})
3535

36+
test('assymeric match', async () => {
37+
const el: any = await $('sel')
38+
el._value = function (): string {
39+
return 'iphone'
40+
}
41+
42+
console.log(el);
43+
44+
const result = await toHaveElementProperty.call({}, el, 'property', expect.stringContaining('phone'))
45+
expect(result.pass).toBe(true)
46+
})
47+
3648
test('should return false if values dont match', async () => {
3749
const el: any = await $('sel')
3850
el._value = function (): string {

test/matchers/element/toHaveValue.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ describe('toHaveValue', () => {
3535
})
3636
})
3737

38+
test('assymetric passes', async () => {
39+
const result = await toHaveValue.call({}, el, expect.stringContaining('example value'))
40+
expect(result.pass).toBe(true)
41+
})
42+
3843
test('RegExp passes', async () => {
3944
const result = await toHaveValue.call({}, el, /ExAmPlE/i)
4045
expect(result.pass).toBe(true)

0 commit comments

Comments
 (0)