Autograder // Input/Output test case Jest

Alright, so this feature is very new and has very little documentation.

The only example I can seem to find for JS testing does not use the input feature, see here, while this is excellent, I would really like to be able to use input for testing.

For example, a slightly modified version of the provided example may have the hello function look something like:

function hello(name = "World") {
    return `Hello ${name}!`;
}

The hello.test.js would look like:

test(`Outputs the correct string`, ()=>{
    //Code to get input and assign to variable "name"
    expect(hello(name)).toBe(`Hello ${name}!`);
}

That way you could run one with no input to verify the default parameter was set, and one with input to ensure it handles input properly.

In my Jest test, how do I get access to these inputs?

I have been looking through the source for the autograding, see here, and it seems like it is trying to use stdin? That makes very little sense to me, so I am sure I must be misunderstanding.

Any advice would be greatly appreciated. An example would have my undying gratitude. Full documentation would be a dream come true.

Hi PasqualeCrea,

Based on that example (and on my own automating Jest tests), what you need to do is have the student’s work file (hello.js in the example) export any values from that module that you want to make available (you can see this with the modules.export = hello line at the bottom). You can then import that module into your test spec, and access those variables (e.g., call the method).

My starter files for JavaScript all contain a block at the bottom that looks like:

//Make functions and variables available to tester. DO NOT MODIFY THIS.
if(typeof module !== 'undefined' && module.exports){
  /* eslint-disable */
  if(typeof hello !== 'undefined') 
    module.exports.hello = hello;
}

And then my test spec contains

const solution = require(pathToStudentSolutionFile); //load the solution

//...

//call student function
solution.hello()

That lets you call the functions from the module to test them.

I understand how to run the tests, the part I can’t seem to figure out is how to access the “Inputs” from the Input/Output test case.

They don’t seem to be in process.argv, and you couldn’t access them with Jest if they were.
They don’t seem to be an environment variable either.

For the life of me I have no clue how it is trying to “Input” these variables for the test cases.
I apologize if my question was unclear.

© 2017 GitHub, Inc.
with by
GitHub Education