diff --git a/README.md b/README.md index 3d5054c..448bb9b 100644 --- a/README.md +++ b/README.md @@ -185,25 +185,35 @@ new Disableautofill('#testForm', { ## Development -### `npm run dev` +#### `npm run dev` Starts a Vite server with hot reload. -### `npm run lint` +![](https://i.imgur.com/OeZhi6a.png) + +This page is the entry point of the development server. You can find it at `http://localhost:9527/`. + +#### `npm run lint` Executes linting by ESLint. -### `npm run test` +#### `npm run test` Runs tests by Vitest. -### `npm run coverage` +#### `npm run coverage` Runs coverage analysis by Vitest. Once you run this command, you can find the coverage report in the `coverage` directory. ``` http://localhost:9527/coverage/ ``` +You will see the coverage report like this: + +![](https://i.imgur.com/4vQxiB0.png) + + + ### Using Docker If Docker is your preferred choice, here's what you need to know. diff --git a/package.json b/package.json index 0bcc005..9715871 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "disableautofill", - "version": "4.0.0-rc.2", + "version": "4.0.0-rc.3", "description": "The easiest solution for disabling Google Chrome auto-fill, auto-complete functions.", "main": "dist/disableautofill.umd.js", "module": "dist/disableautofill.es.js", diff --git a/src/core/main.ts b/src/core/main.ts index 4f82de7..1aa35cf 100644 --- a/src/core/main.ts +++ b/src/core/main.ts @@ -12,9 +12,13 @@ export default class Main { event: EventAdapter | null; state: State; - constructor(formSelector: string, options: Partial) { + constructor(form: string | HTMLFormElement, options: Partial) { + if (form instanceof HTMLFormElement) { + this.form = form; + } else { + this.form = document.querySelector(form) as HTMLFormElement; + } this.setting = { ...config, ...options }; - this.form = document.querySelector(formSelector) as HTMLFormElement; this.clonedForm = this.form?.cloneNode(true) as HTMLFormElement; this.event = null; this.state = new State(); diff --git a/tests/units/main.test.js b/tests/units/main.test.js index da52110..04eed4e 100644 --- a/tests/units/main.test.js +++ b/tests/units/main.test.js @@ -14,6 +14,12 @@ describe('Main class', () => { expect(main.form).not.toBeNull(); }); + test('should initialize with Form element', () => { + const form = document.querySelector('#login-form'); + const main = new Main(form, {}); + expect(main.form).not.toBeNull(); + }); + test('should handle invalid form selector', () => { const originalConsoleError = console.error; console.error = vi.fn();