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

Add random function input Fuzzers? #27

Open
pke opened this issue Jul 12, 2022 · 0 comments
Open

Add random function input Fuzzers? #27

pke opened this issue Jul 12, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@pke
Copy link
Collaborator

pke commented Jul 12, 2022

I have the real-life use case of needing to harden my tested (typescript) functions against invalid input.

Lets say a function under test accepts 2 arguments: an array and a string. Of course TS ensure during writing code that the types match. However, the functions input can also come from user input and/or remote server data and during runtime TS naturally has nothing to say ;)
So I came up with this helper function I think we could add to Fuzzers maybe or better integrate into jest as an expect extension?

function invalidInput(f: Function, expected: any) {
  const testValues = [true, false, 0, "", undefined, null, [], {}]
  testValues.forEach((value) => {
    expect(f.apply(f, new Array(f.length).fill(value))).toBe(expected)
  })
}

It probes the function f with inputs of all kind of inputs: true, false, 0, "", undefined, null, [], {}.
I could imagine having a Fuzzer that can be created from given f and does not generate random values, but those testValues.

What do you think, does this make sense or is this out of scope for fuzzy testing?

@pke pke added the enhancement New feature or request label Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant