How to use the power-assert.true function in power-assert

To help you get started, we’ve selected a few power-assert examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fliphub / fliphub / modules / fosho / index.js View on Github external
const log = require('fliplog')
const power = require('power-assert')
const extend = require('lodash.assigninwith')
const exposeHidden = require('expose-hidden')
const {assert, should, assert2, should2} = require('./chai')
const {lcFirst, ucFirst} = require('./helpers')
const powers = require('./power')
const izz = require('./izz')

// https://github.com/avajs/ava/blob/2a206311d708361b294a21aa4c5bd199936d0824/lib/enhance-assert.js
let Fosho = {}
let debugMode = false
let logMode = false

// compatibility
power.true = power

// log if good to go
function gtg(key, args) {
  if (!logMode) return
  log
    .color('green')
    .text(key + '? fosho')
    .echo()
}

// scope it so it doesn't need to be passed in every time
let scoped = null

// https://github.com/avajs/ava#assertions
const foshizzle = (arg, t) => {
  if (!t && scoped) t = scoped
github fliphub / fliphub / modules / fosho / power.js View on Github external
expected = log.text('expected:').color('green.underline').return().text + '\n\n'
    got = log.text('got:').color('red.underline').return().text + '\n\n'
  }

  txt = log.text(msg + ':').color('bold').return().text + '\n\n'

  return txt + expected + json1 + got + json2
}

const d = (arg1, arg2, msg) => {
  const diffs = log.diff(arg1).diff(arg2).doDiff().return().datas
  const txt = log.text(msg + ':').color('bold').return().text + '\n\n'
  return txt + diffs
}

asspow.true = asspow

class Assert {
  constructor(_obj, ass) {
    this._obj = _obj

    this.aintHasString = (str) =>
      ass.true(!_obj.includes(str), m(_obj, str, 'not include string'))

    this.occurrs = (str, count = 1) =>
      ass.true((_obj.split(str).length - 1) === count, m(count, (_obj.split(str).length - 1), `does not have it times: ${count}`))
    this.hasItTimes = this.occurrs

    this.aintGotString = this.aintHasString
    this.aintGotStr = this.aintHasString
    this.aintNoStr = (str) =>
      ass.true(typeof str !== 'string', m(_obj, str, 'not be a string'))