Test Node.js CLIs with Jest and Oclif

Shawn Wang
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
pery mimon mimon
~ a year ago

where is the expect commands come from ?

Lucas
Lucas
~ a year 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
Kevin Wolf
~ a year 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
Rahul Devaskar
~ a year 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
Ron
~ a year 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"
  } 
}