-
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.
Merge pull request #15 from Turbo87/has-value
Add hasValue() assertion
- Loading branch information
Showing
3 changed files
with
157 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
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,103 @@ | ||
/* eslint-env jest */ | ||
|
||
import TestAssertions from "../helpers/test-assertions"; | ||
|
||
describe('assert.dom(...).hasValue()', () => { | ||
let assert; | ||
|
||
beforeEach(() => { | ||
assert = new TestAssertions(); | ||
|
||
document.body.innerHTML = '<input class="input username">'; | ||
document.querySelector('input.username').value = 'HSimpson'; | ||
}); | ||
|
||
describe('string expected', () => { | ||
test('succeeds for correct content', () => { | ||
assert.dom('input.username').hasValue('HSimpson'); | ||
assert.dom(document.querySelector('input.username')).hasValue('HSimpson'); | ||
|
||
expect(assert.results).toEqual([{ | ||
actual: 'HSimpson', | ||
expected: 'HSimpson', | ||
message: 'Element input.username has value "HSimpson"', | ||
result: true, | ||
}, { | ||
actual: 'HSimpson', | ||
expected: 'HSimpson', | ||
message: 'Element input.input.username has value "HSimpson"', | ||
result: true, | ||
}]); | ||
}); | ||
|
||
test('fails for wrong content', () => { | ||
assert.dom('input.username').hasValue('Bart'); | ||
assert.dom(document.querySelector('input.username')).hasValue('Bart'); | ||
|
||
expect(assert.results).toEqual([{ | ||
actual: 'HSimpson', | ||
expected: 'Bart', | ||
message: 'Element input.username has value "Bart"', | ||
result: false, | ||
}, { | ||
actual: 'HSimpson', | ||
expected: 'Bart', | ||
message: 'Element input.input.username has value "Bart"', | ||
result: false, | ||
}]); | ||
}); | ||
}); | ||
|
||
describe('regex expected', () => { | ||
test('succeeds for correct content', () => { | ||
assert.dom('input.username').hasValue(/.+Simpson/); | ||
assert.dom(document.querySelector('input.username')).hasValue(/.+Simpson/); | ||
|
||
expect(assert.results).toEqual([{ | ||
actual: 'HSimpson', | ||
expected: /.+Simpson/, | ||
message: 'Element input.username has value matching /.+Simpson/', | ||
result: true, | ||
}, { | ||
actual: 'HSimpson', | ||
expected: /.+Simpson/, | ||
message: 'Element input.input.username has value matching /.+Simpson/', | ||
result: true, | ||
}]); | ||
}); | ||
|
||
test('fails for wrong content', () => { | ||
assert.dom('input.username').hasValue(/.+Burns/); | ||
assert.dom(document.querySelector('input.username')).hasValue(/.+Burns/); | ||
|
||
expect(assert.results).toEqual([{ | ||
actual: 'HSimpson', | ||
expected: /.+Burns/, | ||
message: 'Element input.username has value matching /.+Burns/', | ||
result: false, | ||
}, { | ||
actual: 'HSimpson', | ||
expected: /.+Burns/, | ||
message: 'Element input.input.username has value matching /.+Burns/', | ||
result: false, | ||
}]); | ||
}); | ||
}); | ||
|
||
test('fails for missing element', () => { | ||
assert.dom('#missing').hasValue('foo'); | ||
|
||
expect(assert.results).toEqual([{ | ||
message: 'Element #missing exists', | ||
result: false, | ||
}]); | ||
}); | ||
|
||
test('throws for unexpected parameter types', () => { | ||
expect(() => assert.dom(5).hasValue('foo')).toThrow('Unexpected Parameter: 5'); | ||
expect(() => assert.dom(true).hasValue('foo')).toThrow('Unexpected Parameter: true'); | ||
expect(() => assert.dom(undefined).hasValue('foo')).toThrow('Unexpected Parameter: undefined'); | ||
expect(() => assert.dom({}).hasValue('foo')).toThrow('Unexpected Parameter: [object Object]'); | ||
expect(() => assert.dom(document).hasValue('foo')).toThrow('Unexpected Parameter: [object HTMLDocument]'); | ||
}); | ||
}); |
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