all files / workspace/ test.js

100% Statements 47/47
100% Branches 0/0
100% Functions 0/0
100% Lines 47/47
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94        10×               21×         10×         42×                                                        
'use strict'
 
const expect = require('chai').expect
const froth = require('./index')
 
describe('Default settings', () => {
  
  it('should return a 10-item array of strings with 20 characters or less by default', () => {
    const output = froth()
    expect(output).to.be.an('array').and.to.have.lengthOf(10)
    output.forEach( (item) => {
      expect(item).to.be.a('string').and.not.to.have.lengthOf.above(20)
    })
  })
  
})
 
describe('Changing number of strings and maximum length', () => {
  
  it('should return a different number of strings', () => {
    // Generate a random number from 1 to 50
    const test_num = Math.floor(Math.random()*51)
    const output = froth(test_num)
    expect(output).to.be.an('array').and.to.have.lengthOf(test_num)
    output.forEach( (item) => {
      expect(item).to.be.a('string').and.not.to.have.lengthOf.above(20)
    })
  })
  
  it('should return strings with a different maximum length', () => {
    // Generate a random number from 1 to 50
    const test_max = Math.floor(Math.random()*51)
    const output = froth(undefined, test_max)
    expect(output).to.be.an('array').and.to.have.lengthOf(10)
    output.forEach( (item) => {
      expect(item).to.be.a('string').and.not.to.have.lengthOf.above(test_max)
    })
  })
  
  it('should return a different number of strings with a different maximum length', () => {
    // Generate two random number from 1 to 50
    const test_num = Math.floor(Math.random()*51)
    const test_max = Math.floor(Math.random()*51)
    const output = froth(test_num, test_max)
    expect(output).to.be.an('array').and.to.have.lengthOf(test_num)
    output.forEach( (item) => {
      expect(item).to.be.a('string').and.not.to.have.lengthOf.above(test_max)
    })
  })
  
})
 
describe('Changing options', () => {
  
  it('should not return blank strings when \'none=false\' is specified', () => {
    const output = froth(100, 100, {none:false})
    expect(output).to.be.an('array').and.to.not.contain('')
  })
  
  it('should not return whitespaces when \'whitespace=false\' is specified', () => {
    const output = froth(100, 100, {whitespace:false})
    expect(output).to.be.an('array').and.to.not.contain(' ','  ','\n','\r\n','\r')
  })
  
  it('should not return quotations when \'quotes=false\' is specified', () => {
    const output = froth(100, 100, {quotes:false})
    expect(output).to.be.an('array').and.to.not.contain(
      '\'', '\'\'', '\'\'\'', '"', '""', '"""', '`', '``', '```'
    )
  })
  
  it('should not return symbols when \'symbols=false\' is specified', () => {
    const output = froth(100, 100, {quotes:false})
    expect(output).to.be.an('array').and.to.not.contain(
      ...'°~!@#$%€^&*()-_─=+[]{}|;:,./<>?¿¹²³¼½¬€¶←↓→»«¢„“”·…–'.split('')
    )
  })
  
  it('should not return foreign characters when \'foreign=false\' is specified', () => {
    const output = froth(100, 100, {quotes:false})
    expect(output).to.be.an('array').and.to.not.contain(
      ...'ŧłßöäüñáóíúýéâêîôûŷàèìòùảẻỉỏỷÿïøþłĸŋđðſæµёйцукенгшщзхъэждлорпавыфячсмитьбюЁЙЦУКЕНГШЩЗХЪЭЖДЛОРПАВЫФЯЧСМИТЬБЮ'.split('')
    )
  })
  
  it('should not return numbers or letters when \'alphanumeric=false\' is specified', () => {
    const output = froth(100, 100, {quotes:false})
    expect(output).to.be.an('array').and.to.not.contain(
      ...'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'.split('')
    )
  })
  
})