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

Can't use otherwise in Jest tests #1

Open
erkannt opened this issue Nov 10, 2021 · 0 comments
Open

Can't use otherwise in Jest tests #1

erkannt opened this issue Nov 10, 2021 · 0 comments

Comments

@erkannt
Copy link

erkannt commented Nov 10, 2021

Been playing with this as I like the simplicity of your approach.

Whenever I use otherwise Jest tests covering that code break. Minimal example in the existing index.spec.ts:

  it("using `otherwise` allows `run` in cases where `when`s are not exhaustive", () => {
    const matcher = match(3 as number | string)
      .when( isString, (_) => "it is string")
      .otherwise(() => 'no case matched, resulting to default')

    type _ = Expect<Equal<typeof matcher, BuiltMatch<string>>>;
    expect(matcher.run()).toBe('no case matched, resulting to default')
  })

This results in the following failure:

  ● match › using `otherwise` allows `run` in cases where `when`s are not exhaustive

    TypeError: Cannot read property 'run' of undefined

      39 |
      40 |     type _ = Expect<Equal<typeof matcher, BuiltMatch<string>>>;
    > 41 |     expect(matcher.run()).toBe('no case matched, resulting to default')
         |                    ^
      42 |   })
      43 | });
      44 |

      at Object.<anonymous> (test/index.spec.ts:41:20)

Commit of this as a skipped test available on my fork.

If you have any ideas how to tackle this I'm happy to tinker and prepare a PR. Currently I'm out of ideas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant