zoukankan      html  css  js  c++  java
  • [Unit testing] Improve Error Messages by Generating Test Titles

    One of the most crucial things you can do when writing tests is ensuring that the error message explains the problem as clearly as possible so it can be addressed quickly. Let’s improve our test by generating test titles so error messages are more descriptive.

    //auth.js
    
    function isPasswordAllowed(password) {
      return (
        password.length > 6 &&
        // non-alphanumeric
        /W/.test(password) &&
        // digit
        /d/.test(password) &&
        // capital letter
        /[A-Z]/.test(password) &&
        // lowercase letter
        /[a-z]/.test(password)
      )
    }
    import {isPasswordAllowed} from '../auth'
    
    describe('isPasswordAllowed', () => {
      const allowedPwds = ['!aBc123']
      const disallowedPwds = {
        'too short': 'a2c!',
        'no alphabet characters': '123456',
        'no numbers': 'ABCdef!',
        'no uppercase letters': 'abc123!',
        'no lowercase letters': 'ABC123!',
        'no non-alphanumeric characters': 'ABCdef123',
      }
      allowedPwds.forEach((pwd) => {
        test(`allow ${pwd}`, () => {
          expect(isPasswordAllowed(pwd)).toBeTruthy()
        })
      })
      Object.entries(disallowedPwds).forEach(([key, value]) => {
        test(`disallow - ${key}: ${value}`, () => {
          expect(isPasswordAllowed(value)).toBeFalsy()
        })
      })
    })

  • 相关阅读:
    如何搭建PHP本地服务器
    load xml with xls
    t-sql read xlsx
    test js online link
    export to pdf
    silverlight browse information
    ckeditor link
    T-Sql操作Xml数据(转)
    Linq to Xml
    webpack -p压缩打包react报语法错误处理
  • 原文地址:https://www.cnblogs.com/Answer1215/p/15104821.html
Copyright © 2011-2022 走看看