-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
243 additions
and
86 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,62 @@ | ||
import {FormToObject} from "../../src/FormToObject"; | ||
|
||
describe('constructor', () => { | ||
describe('An invalid or non existing selector', () => { | ||
it('null, should throw error', () => { | ||
expect(() => { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
new FormToObject(null); | ||
}).toThrowError('No selector was passed.'); | ||
}); | ||
|
||
it('empty string, should throw error', () => { | ||
expect(() => { | ||
new FormToObject(''); | ||
}).toThrowError('No selector was passed.'); | ||
}); | ||
|
||
it('undefined, should throw error', () => { | ||
expect(() => { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
new FormToObject(); | ||
}).toThrowError('No selector was passed.'); | ||
}); | ||
|
||
it('non-existent selector should throw error', () => { | ||
expect(() => { | ||
new FormToObject('non-existing-selector'); | ||
}).toThrowError('The <form> DOM element could not be found.'); | ||
}); | ||
|
||
it('invalid DOM element ref should throw error', () => { | ||
expect(() => { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
new FormToObject(document.createTextNode('text')); | ||
}).toThrowError('The <form> DOM element could not be found.'); | ||
}); | ||
|
||
it('invalid class should throw error', () => { | ||
expect(() => { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
new FormToObject({nodeType: 1}); | ||
}).toThrowError('The <form> is either not a valid DOM element or the browser is very old.'); | ||
}); | ||
|
||
}); | ||
|
||
describe('An empty HTML form', () => { | ||
it('should return throw error', () => { | ||
expect(() => { | ||
const $form = document.createElement('form'); | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
new FormToObject($form); | ||
}).toThrowError('No <form> DOM elements were found. Form is empty.'); | ||
}); | ||
}); | ||
}); | ||
|
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,36 @@ | ||
import {FormToObject} from "../../src/FormToObject"; | ||
|
||
describe('submit', () => { | ||
it('input with includeSubmitButton: true', () => { | ||
const $form = document.createElement('form'); | ||
$form.innerHTML = ` | ||
<input type="submit" name="submit" value="go"> | ||
`; | ||
const formToObject = new FormToObject($form, {includeSubmitButton: true}); | ||
|
||
expect(formToObject.convertToObj()).toEqual({'submit':'go'}); | ||
}); | ||
|
||
it('input with includeSubmitButton: false (default)', () => { | ||
const $form = document.createElement('form'); | ||
$form.innerHTML = ` | ||
<input type="submit" name="submit" value="go"> | ||
`; | ||
const formToObject = new FormToObject($form); | ||
|
||
expect(formToObject.convertToObj()).toEqual({}); | ||
}); | ||
|
||
// Currently we don't support <button>. Should we? | ||
it('button', () => { | ||
expect(() => { | ||
const $form = document.createElement('form'); | ||
$form.innerHTML = ` | ||
<button type="submit" name="submit">go</button> | ||
`; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
new FormToObject($form); | ||
}).toThrowError('No <form> DOM elements were found. Form is empty.'); | ||
}); | ||
}); |
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,13 @@ | ||
import {FormToObject} from "../../src/FormToObject"; | ||
|
||
describe('textarea', ()=> { | ||
it('should return an object', () => { | ||
const $form = document.createElement('form'); | ||
$form.innerHTML = ` | ||
<textarea name="address">address</textarea> | ||
`; | ||
const formToObject = new FormToObject($form); | ||
|
||
expect(formToObject.convertToObj()).toEqual({'address':'address'}); | ||
}); | ||
}); |
Oops, something went wrong.