Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test environment #7

Closed
wants to merge 14 commits into from
Closed

Test environment #7

wants to merge 14 commits into from

Conversation

sstephenson
Copy link
Contributor

@sstephenson sstephenson commented Oct 19, 2017

Provides a TestEnvironment class that helps test a Stimulus application, with methods for loading HTML fixtures, finding connected controllers, finding elements, and simulating events.

Create and stash a TestEnvironment in your test framework’s setup hook:

setup() {
  this.t = TestEnvironment.setup(document.getElementById("fixture"), {
    "expandable": ExpandableController
  })
}

And destroy it in the teardown hook:

teardown() {
  this.t.teardown()
}

Load a fixture before making assertions:

await this.t.loadFixture(`
  <div data-controller="expandable">
    <button data-action="expandable#expand">Expand</button>
  </div>
`)

Trigger a simulated click event on the button:

await this.t.triggerEvent("click", "button")

Find the connected controller instance and assert controller state:

const controller = this.t.findController("expandable")
assert.ok(controller.isExpanded)

Find elements and assert DOM state:

const element = this.t.findElement({ controller: "expandable" })
assert.ok(element.classList.has("expanded"))

"packages/*/index.ts",
"packages/@stimulus/*/src/**/*.ts",
"packages/@stimulus/*/test/**/*.ts",
"packages/@stimulus/*/index.ts"
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With your package.json "dist" changes, I think we can chop this down to:

"include": [
  "packages/**/*.ts"
]

@javan javan mentioned this pull request Jan 4, 2018
@sstephenson sstephenson added this to the 1.0 milestone Jan 10, 2018
@sstephenson
Copy link
Contributor Author

Closing in favor of #58.

@sstephenson sstephenson deleted the test-environment branch January 13, 2018 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants