-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* eslint-env jest */ | ||
|
||
import TestAssertions from '../helpers/test-assertions'; | ||
|
||
describe('assert.dom(...).hasProperty()', () => { | ||
let assert: TestAssertions; | ||
|
||
beforeEach(() => { | ||
assert = new TestAssertions(); | ||
|
||
document.body.innerHTML = '<input type="password">'; | ||
}); | ||
|
||
describe('string expected', () => { | ||
test('succeeds for correct name and value', () => { | ||
assert.dom('input').hasProperty('type', 'password'); | ||
assert.dom(document.querySelector('input')).hasProperty('type', 'password'); | ||
|
||
expect(assert.results).toEqual([ | ||
{ | ||
actual: 'Element input has property "type" with value "password"', | ||
expected: 'Element input has property "type" with value "password"', | ||
message: 'Element input has property "type" with value "password"', | ||
result: true, | ||
}, | ||
{ | ||
actual: 'Element input[type="password"] has property "type" with value "password"', | ||
expected: 'Element input[type="password"] has property "type" with value "password"', | ||
message: 'Element input[type="password"] has property "type" with value "password"', | ||
result: true, | ||
}, | ||
]); | ||
}); | ||
|
||
test('fails for wrong value', () => { | ||
assert.dom('input').hasProperty('type', 'text'); | ||
assert.dom(document.querySelector('input')).hasProperty('type', 'text'); | ||
|
||
expect(assert.results).toEqual([ | ||
{ | ||
actual: 'Element input has property "type" with value "password"', | ||
expected: 'Element input has property "type" with value "text"', | ||
message: 'Element input has property "type" with value "text"', | ||
result: false, | ||
}, | ||
{ | ||
actual: 'Element input[type="password"] has property "type" with value "password"', | ||
expected: 'Element input[type="password"] has property "type" with value "text"', | ||
message: 'Element input[type="password"] has property "type" with value "text"', | ||
result: false, | ||
}, | ||
]); | ||
}); | ||
}); | ||
|
||
describe('regex expected', () => { | ||
test('succeeds for matching name and value', () => { | ||
assert.dom('input').hasProperty('type', /^pass/); | ||
assert.dom(document.querySelector('input')).hasProperty('type', /^pass/); | ||
|
||
expect(assert.results).toEqual([ | ||
{ | ||
actual: 'Element input has property "type" with value "password"', | ||
expected: 'Element input has property "type" with value matching /^pass/', | ||
message: 'Element input has property "type" with value matching /^pass/', | ||
result: true, | ||
}, | ||
{ | ||
actual: 'Element input[type="password"] has property "type" with value "password"', | ||
expected: | ||
'Element input[type="password"] has property "type" with value matching /^pass/', | ||
message: 'Element input[type="password"] has property "type" with value matching /^pass/', | ||
result: true, | ||
}, | ||
]); | ||
}); | ||
|
||
test('fails for wrong value', () => { | ||
assert.dom('input').hasProperty('type', /mail$/); | ||
assert.dom(document.querySelector('input')).hasProperty('type', /mail$/); | ||
|
||
expect(assert.results).toEqual([ | ||
{ | ||
actual: 'Element input has property "type" with value "password"', | ||
expected: 'Element input has property "type" with value matching /mail$/', | ||
message: 'Element input has property "type" with value matching /mail$/', | ||
result: false, | ||
}, | ||
{ | ||
actual: 'Element input[type="password"] has property "type" with value "password"', | ||
expected: | ||
'Element input[type="password"] has property "type" with value matching /mail$/', | ||
message: 'Element input[type="password"] has property "type" with value matching /mail$/', | ||
result: false, | ||
}, | ||
]); | ||
}); | ||
}); | ||
|
||
test('fails for missing element', () => { | ||
assert.dom('#missing').hasProperty('foo', 'bar'); | ||
|
||
expect(assert.results).toEqual([ | ||
{ | ||
message: 'Element #missing should exist', | ||
result: false, | ||
}, | ||
]); | ||
}); | ||
|
||
test('throws for unexpected parameter types', () => { | ||
//@ts-ignore -- These assertions are for JavaScript users who don't have type checking | ||
expect(() => assert.dom(5).hasProperty('foo', 'bar')).toThrow('Unexpected Parameter: 5'); | ||
//@ts-ignore | ||
expect(() => assert.dom(true).hasProperty('foo', 'bar')).toThrow('Unexpected Parameter: true'); | ||
expect(() => assert.dom(undefined).hasProperty('foo', 'bar')).toThrow( | ||
'Unexpected Parameter: undefined' | ||
); | ||
//@ts-ignore | ||
expect(() => assert.dom({}).hasProperty('foo', 'bar')).toThrow( | ||
'Unexpected Parameter: [object Object]' | ||
); | ||
//@ts-ignore | ||
expect(() => assert.dom(document).hasProperty('foo', 'bar')).toThrow( | ||
'Unexpected Parameter: [object Document]' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters