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()
        })
      })
    })

  • 相关阅读:
    新服务器上迁移项目遇到的问题
    xftp传输文件失败
    记录一些mysql常用命令
    微信APP支付
    状态码(更新中···)
    yii ActiveRecord
    MySQL命令行自动补全——mycli安装
    MySQL优化总结
    MySQL读写分离架构——Atlas
    MySQL日志
  • 原文地址:https://www.cnblogs.com/Answer1215/p/15104821.html
Copyright © 2011-2022 走看看