Welcome to the Linux Foundation Forum!

Regarding Lab 16.3

When running the validate.js I get the message "AssertionError [ERR_ASSERTION]: error case should be tested". I believe my test routine works for success, digits !=4 and value not a Buffer so I am not sure what is being tested for that I am failing to capture. I purposefully don't want any code help, therefore I would appreciate a confirmation that I should keep looking!. I have the latest Jan 5 labs. Thanks.

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Answers

  • hey @bryan.pedersen this error means that the process is exiting with a non-zero exit code because an error isn't being handled. The assertion modifies the store.js file so that input isn't validated - the idea is to generate an unexpected error. If the process is exiting with a non-zero code it means that unexpected errors haven't been handled.

  • Have same issue, and not sure how I should get unexpected error if there's no validation in validation.js for that:

    Spoiler

    1. const badValidation = `'use strict'
    2. const { promisify } = require('util')
    3. const timeout = promisify(setTimeout)
    4. module.exports = async (value) => {
    5. await timeout(300)
    6. const id = Math.random().toString(36).split('.')[1].slice(0, 4)
    7. return { id }
    8. }
    9. `
    10.  
    11. writeFileSync(store, badValidation)
    12.  
    13. const sp = spawnSync(process.platform === 'win32' ? 'npm.cmd' : 'npm', ['test'], {
    14. env: { ...process.env, NODE_OPTIONS: '--unhandled-rejections=strict' },
    15. stdio: 'ignore'
    16. })
    17.  
    18. assert.equal(sp.status, 1, 'error case should be tested')

    So, what should cause that test that exit with code: 1? if we don't use anyway value parameter?

  • Posts: 160

    @industral the validation logic overwrites the spawned file so that it causes a throw in your code, that throw creates the non-zero exit - you have to error-handle the case in your code

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training