Testy / TestyTs

✔️ Modern TypeScript testing framework.
http://testy.github.io
ISC License
123 stars 8 forks source link

@TestCase decorator #25

Closed Aboisier closed 5 years ago

Aboisier commented 5 years ago

The current test case syntax is pretty ugly in my opinion.

@Test('My test', [
      new TestCase('Two plus two is four', 2, 2, 4),
      new TestCase(`Minus one that's three`, 4, -1, 3)
])
quickMaths(a: number, b: number, result: number) {
    expect.toBeEqual(a + b, result);
}

I think we can improve this. Here are a few examples of how we could go about it:

I like this syntax, but I'm not sure where we would put the timeout parameter, and we lose the opportunity to have a custom root-test name.

@TestCase('Two plus two is four', 2, 2, 4)
@TestCase(`Minus one that's three`, 4, -1, 3)
quickMaths(a: number, b: number, result: number) {
    expect.toBeEqual(a + b, result);
}

This option solves the name and timeout parameters problem and is still more readable than the current implementation.

@Test()
@TestCase('Two plus two is four', 2, 2, 4)
@TestCase(`Minus one that's three`, 4, -1, 3)
quickMaths(a: number, b: number, result: number) {
    expect.toBeEqual(a + b, result);
}
bryanmenard commented 5 years ago

I like the proposed syntax. However, I think having a separate decorator for the timeout (@Timeout) would be a good solution, too.

I think it's cleaner for regular tests (avoids having to pass empty arguments when we need a timeout but no test name) and also solves this issue.

Aboisier commented 5 years ago

I really like this solution! I was definitely pretty annoyed by the empty argument.

Aboisier commented 5 years ago

Implemented in #29 .