Welcome to the Linux Foundation Forum!

Regarding Lab 16.3

Options

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.

Answers

  • davidmarkclements
    Options

    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.

  • industral
    Options

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

    const badValidation = `'use strict'
      const { promisify } = require('util')
      const timeout = promisify(setTimeout)
      module.exports = async (value) => {
        await timeout(300)
        const id = Math.random().toString(36).split('.')[1].slice(0, 4)
        return { id }
      }
    `
    
    writeFileSync(store, badValidation)
    
    const sp = spawnSync(process.platform === 'win32' ? 'npm.cmd' : 'npm', ['test'], {
      env: { ...process.env, NODE_OPTIONS: '--unhandled-rejections=strict' },
      stdio: 'ignore'
    })
    
    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?

  • xdxmxc
    xdxmxc Posts: 139
    Options

    @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

Categories

Upcoming Training