Skip to content

Commit

Permalink
add test to verify duplicate controller are not registered
Browse files Browse the repository at this point in the history
  • Loading branch information
nachiket87 committed Nov 9, 2023
1 parent 9aa2429 commit c55a28b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/fixtures/controllers/hello_controller.ts
Original file line number Diff line number Diff line change
@@ -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}!`
}

}
3 changes: 3 additions & 0 deletions test/manifest_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)'
Expand Down

0 comments on commit c55a28b

Please sign in to comment.