Skip to content

Commit

Permalink
Return of invalid form data is undefined
Browse files Browse the repository at this point in the history
Included back the test files into tsconfig
Changed build/ paths.
  • Loading branch information
serbanghita committed Dec 9, 2023
1 parent 55414c5 commit 4f81d78
Show file tree
Hide file tree
Showing 26 changed files with 43 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
cache: 'npm'
- run: npm ci
- run: npm run build
- run: npm run test:unit-and-acceptance
- run: npm run test
- run: npm run test:e2e

- name: Upload coverage reports to Codecov
Expand Down
4 changes: 2 additions & 2 deletions build/FormToObject.d.ts → build/src/FormToObject.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export declare class FormToObject {
initForm(): boolean;
initFormElements(): boolean;
convertToObj(): any;
getNodeValues($domNode: HTMLFormField): string | false | FileList | string[] | null;
processSingleLevelNode($domNode: HTMLFormField, arr: Array<string | number>, domNodeValue: string | number | boolean | FileList | string[], result: Record<string, string | number | boolean | FileList | string[] | unknown[]>): string | number | boolean | FileList | string[] | undefined;
getNodeValues($domNode: HTMLFormField): string | false | string[] | FileList | null;
processSingleLevelNode($domNode: HTMLFormField, arr: Array<string | number>, domNodeValue: string | number | boolean | FileList | string[], result: Record<string, string | number | boolean | FileList | string[] | unknown[]>): string | number | boolean | string[] | FileList | undefined;
processMultiLevelNode($domNode: HTMLFormField, arr: Array<string | number>, value: string | number | boolean | FileList | string[], result: NodeResult): void;
formElementHasSiblings($domNode: HTMLFormField): boolean;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions build/test/e2e/smoke.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
7 changes: 7 additions & 0 deletions build/test/helpers.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { expect } from '@jest/globals';
import { TestingLibraryMatchers } from '@testing-library/jest-dom/matchers';
export declare function readIntegrationFixture(relativePath: string): string;
declare module 'expect' {
interface Matchers<R = void> extends TestingLibraryMatchers<typeof expect.stringContaining, R> {
}
}
1 change: 1 addition & 0 deletions build/test/integration/checkbox.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions build/test/integration/complexForms.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions build/test/integration/exceptions.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions build/test/integration/input.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions build/test/integration/radio.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions build/test/integration/select.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions build/test/integration/textarea.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions build/test/integration/unexpected.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions build/test/unit/checkForLastNumericKey.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions build/test/unit/extend.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions build/test/unit/getLastIntegerKey.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions build/test/unit/getNextIntegerKey.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions build/test/unit/getObjLength.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions build/test/unit/isDomElementNode.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"homepage": "https://github.com/serbanghita/formToObject",
"author": "Serban Ghita <[email protected]>",
"main": "build/bundle/formToObject.min.js",
"types": "build/index.d.ts",
"types": "build/src/index.d.ts",
"sideEffects": false,
"repository": {
"type": "git",
Expand All @@ -26,7 +26,7 @@
"scripts": {
"build": "webpack --mode production",
"dev": "webpack --mode development -d inline-source-map --watch",
"test:unit-and-acceptance": "jest",
"test": "jest",
"test:e2e": "wdio run ./wdio.conf.ts"
},
"devDependencies": {
Expand Down Expand Up @@ -55,7 +55,6 @@
"typescript": "^5.2.2",
"wdio-wait-for": "^3.0.7",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0",
"webpack-merge": "^5.10.0"
"webpack-cli": "^4.10.0"
}
}
20 changes: 10 additions & 10 deletions test/integration/exceptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ import {readIntegrationFixture} from "../helpers";

describe('exceptions', () => {
describe('An invalid or non existing selector', () => {
test('should return false if null is passed as argument', () => {
test('should return undefined if null is passed as argument', () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
expect(formToObject(null)).toBe(false);
expect(formToObject(null)).toBeUndefined();
});

test('should return false if an empty string is passed as argument', () => {
expect(formToObject('')).toBe(false);
test('should return undefined if an empty string is passed as argument', () => {
expect(formToObject('')).toBeUndefined();
});

test('should return false if undefined object is passed', () => {
test('should return undefined if undefined object is passed', () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
expect(formToObject(undefined)).toBe(false);
expect(formToObject(undefined)).toBeUndefined();
});

test('should return false if the argument passed is invalid', () => {
expect(formToObject('newFormUndefined')).toBe(false);
test('should return undefined if the argument passed is invalid', () => {
expect(formToObject('newFormUndefined')).toBeUndefined();
});
});

describe('An empty HTML form', () => {
test('should return false if the form has no elements', () => {
test('should return undefined if the form has no elements', () => {
document.body.innerHTML = readIntegrationFixture("other/exceptions/empty-form.html");
const $form = screen.queryByTestId('testForm') as HTMLFormElement;

expect(formToObject($form)).toBe(false);
expect(formToObject($form)).toBeUndefined();
});
});
});
Expand Down
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"types": ["node", "jest", "mocha", "@testing-library/jest-dom"]
},
"include": [
"src/index.ts"
"src/index.ts",
"test/unit/*",
"test/integration/*",
"test/e2e/*"
],
"exclude": [
"node_modules",
Expand Down

0 comments on commit 4f81d78

Please sign in to comment.