Test Node.js CLIs with Jest and Oclif

InstructorShawn Wang

Share this video with your friends

Send Tweet

To be useful and trustworthy, your CLIs should be extraordinarily reliable. Investing in testing early will reap rewards in future. We show how to set up basic tests with Jest and Oclif's test helpers.

pery mimon mimon
~ 4 years ago

where is the expect commands come from ?

Lucas Minter
~ 4 years ago

where is the expect commands come from?

The expect command is apart of jest and is used to run tests. expect is used to tell the computer what the output should be.

Kevin Wolf
~ 4 years ago

Thanks for this valuable lesson, Shawn. I have a couple of questions:

  1. Why do you suggest using Jest instead of Mocha? (current version scaffolds tests using Mocha).
  2. To avoid the newline problem is it better to add the /n at the end or expect(ctx.stdout.trim()).toBe('whatever')?

Thanks!

Rahul Devaskar
~ 4 years ago

thanks for the lesson. I tried running tests using yarn jest but I'm getting command <name> not found error. Does anyone know how to fix this?

Ron
~ 4 years ago

thanks for the lesson. I tried running tests using yarn jest but I'm getting command <name> not found error. Does anyone know how to fix this? You need to put jest as as a script in package.json like below:

{
  "scripts": {
      "jest": "jest"
  } 
}