From c55a28b7bbdcf45a0443bf97d258a31920b1f8ab Mon Sep 17 00:00:00 2001 From: Nachiket Pusalkar <33430835+nachiket87@users.noreply.github.com> Date: Thu, 9 Nov 2023 11:59:29 -0500 Subject: [PATCH] add test to verify duplicate controller are not registered --- test/fixtures/controllers/hello_controller.ts | 15 +++++++++++++++ test/manifest_test.rb | 3 +++ 2 files changed, 18 insertions(+) create mode 100644 test/fixtures/controllers/hello_controller.ts diff --git a/test/fixtures/controllers/hello_controller.ts b/test/fixtures/controllers/hello_controller.ts new file mode 100644 index 0000000..9ae5f32 --- /dev/null +++ b/test/fixtures/controllers/hello_controller.ts @@ -0,0 +1,15 @@ +// hello_controller.ts +import { Controller } from "stimulus"; + +export default class extends Controller { + static targets = ["name", "output"]; + + declare readonly nameTarget: HTMLInputElement; + declare readonly outputTarget: HTMLElement; + + greet() { + this.outputTarget.textContent = + `Hello, ${this.nameTarget.value}!` + } + +} diff --git a/test/manifest_test.rb b/test/manifest_test.rb index eb9de3a..f5ef21a 100644 --- a/test/manifest_test.rb +++ b/test/manifest_test.rb @@ -9,6 +9,9 @@ class Stimulus::Manifest::Test < ActiveSupport::TestCase assert_includes manifest, 'import HelloController from "./hello_controller"' assert_includes manifest, 'application.register("hello", HelloController)' + assert_equal 1, manifest.scan('import HelloController from "./hello_controller"').length + assert_equal 1, manifest.scan('application.register("hello", HelloController').length + # CoffeeScript controller assert_includes manifest, 'import CoffeeController from "./coffee_controller"' assert_includes manifest, 'application.register("coffee", CoffeeController)'