-
Notifications
You must be signed in to change notification settings - Fork 0
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
jonacs
committed
Nov 27, 2023
1 parent
20eb614
commit 45b8e7a
Showing
4 changed files
with
55 additions
and
3 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
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,35 @@ | ||
import InputValidator from '../src/inputValidator'; | ||
|
||
test('Valid Equal to', () => { | ||
expect(InputValidator.isEqualTo('10', '10')).toBe(true); | ||
}); | ||
|
||
test('Invalid Equal to', () => { | ||
expect(InputValidator.isEqualTo('10', '20')).toBe(false); | ||
}); | ||
|
||
test('Check if equalTo custom error message is applied', () => { | ||
// Create a container div to hold the input and potential error div | ||
const containerDiv = document.createElement('div'); | ||
|
||
// Create an input element | ||
const inputElement = document.createElement('input'); | ||
inputElement.value = '10'; | ||
|
||
// Append the input to the container | ||
containerDiv.appendChild(inputElement); | ||
|
||
// Validation parameters and messages | ||
const validationParams = { "equalTo": '20' }; | ||
const validationMessages = { "equalTo": 'Inputs do not match!' }; | ||
|
||
// Assuming your InputValidator inserts an error message as a sibling | ||
InputValidator.validateInput(inputElement, validationParams, validationMessages); | ||
|
||
// Check if the error message is inserted as a sibling to the input | ||
const errorMessageDiv = inputElement.nextElementSibling; | ||
|
||
expect(errorMessageDiv).not.toBeNull(); | ||
expect(errorMessageDiv.classList.contains('invalid-feedback')).toBe(true); | ||
expect(errorMessageDiv.innerHTML).toBe('Inputs do not match!'); | ||
}); |