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

Expand testing with negation and error handling #458

Open
bbugh opened this issue Jun 6, 2021 · 0 comments
Open

Expand testing with negation and error handling #458

bbugh opened this issue Jun 6, 2021 · 0 comments
Labels
discussion stdlib Standard library related tooling Tooling related feature (formatter, documentation, production builder)

Comments

@bbugh
Copy link
Contributor

bbugh commented Jun 6, 2021

Raised from trying to add tests for #453. I need to check a != 0 or > 0, which does not seem to be available in the testing framework. Since it's written in JavaScript and fails based on exceptions, I have tried to think of the least impactful change to get negation if the expectation is to keep the testing framework using inline JavaScript and not Mint.

I could add an assertNotEqual or an assertNotTextOf (which is a weird name), but it seems like adding negation like other test frameworks do would be a better result.

<Test.Provider.AnimationFrame/>
|> start()
|> not(assertTextOf("something", "value"))

/* or */

|> assertTextOf.not("something", "value")

/* or */

|> Assert.not.textOf("something", "value")

/* or */

|> not(() : { assertTextOf("something", "value") })

The trouble with this is that not finding a selector is not the same as the test passing. This could be handled with custom Error types, rather than catching any exception. You could leave the regular exception errors for test implementation failures, and then raise an AssertionFailure (or something) that gets handled differently when caught. For example, is assertTextOf with only a change to throw an AssertionFailure.

fun assertTextOf (
  selector : String,
  value : String,
  context : Test.Context(Dom.Element)
) : Test.Context(Dom.Element) {
  `
  #{context}.step((element) => {
    let text = "";

    try {
      text = element.querySelector(#{selector}).textContent
    } catch (error) {
      throw \`Could not find element with selector: ${#{selector}}\`
    }

    if (text == #{value}) {
      return element
    } else {
      throw new AssertionFailure(\`"${text}" != "${#{value}}"\`) 🆕
    }
  })
  `
}
@Sija Sija added discussion stdlib Standard library related tooling Tooling related feature (formatter, documentation, production builder) labels Jun 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion stdlib Standard library related tooling Tooling related feature (formatter, documentation, production builder)
Development

No branches or pull requests

2 participants