Extract and set form values through the DOM—no frameworks required! https://github.com/TheoryOfNekomata/formxtra
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

83 rader
2.0 KiB

  1. import getFormValues from '../../src'
  2. import * as utils from '../utils'
  3. describe('checkbox', () => {
  4. describe('basic', () => {
  5. beforeEach(utils.setup(`
  6. <!DOCTYPE html>
  7. <html lang="en-PH">
  8. <head>
  9. <meta charset="UTF-8">
  10. <title>Checkbox/Basic</title>
  11. </head>
  12. <body>
  13. <form>
  14. <label>
  15. <span>Hello</span>
  16. <input type="checkbox" name="enabled" />
  17. </label>
  18. <button type="submit">Submit</button>
  19. </form>
  20. </body>
  21. </html>
  22. `))
  23. it('should have no form values', () => {
  24. utils.test(
  25. (cy: any) => cy.get('[type="submit"]'),
  26. (form: HTMLFormElement, submitter: any, search: any) => {
  27. const values = getFormValues(form, {submitter})
  28. const before = utils.makeSearchParams(values).toString();
  29. const after = utils.makeSearchParams(search).toString();
  30. expect(values['enabled']).toBeUndefined();
  31. expect(before).toEqual(after);
  32. },
  33. ''
  34. );
  35. });
  36. it('should have false checked value', () => {
  37. utils.test(
  38. (cy: any) => cy.get('[type="submit"]'),
  39. (form: HTMLFormElement, submitter: any, search: any) => {
  40. const values = getFormValues(form, {submitter, booleanValuelessCheckbox: true })
  41. expect(values['enabled']).toBe(false);
  42. }
  43. );
  44. });
  45. })
  46. describe('checked', () => {
  47. beforeEach(utils.setup(`
  48. <!DOCTYPE html>
  49. <html lang="en-PH">
  50. <head>
  51. <meta charset="UTF-8">
  52. <title>Checkbox/Checked</title>
  53. </head>
  54. <body>
  55. <form>
  56. <label>
  57. <span>Hello</span>
  58. <input type="checkbox" name="enabled" checked />
  59. </label>
  60. <button type="submit">Submit</button>
  61. </form>
  62. </body>
  63. </html>
  64. `))
  65. it('should have single form value on a single field', () => {
  66. utils.test(
  67. (cy: any) => cy.get('[type="submit"]'),
  68. (form: HTMLFormElement, submitter: any, search: any) => {
  69. const before = utils.makeSearchParams(getFormValues(form, {submitter})).toString();
  70. const after = utils.makeSearchParams(search).toString();
  71. expect(before).toEqual(after);
  72. },
  73. 'enabled=on'
  74. );
  75. });
  76. })
  77. })