npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chai-yaml

v0.0.16

Published

Chai plugin for YAML

Downloads

16

Readme

chai-yaml

YAML Assertions for Chai

Usage

const chai = require('chai')
const chaiYaml = require('chai-yaml');

chai.use(chaiYaml)

Peer/Dev Dependencies

| Name | Version | | -------------------------------------- | -------- | | chai | ^4.6.0 | | yaml | ^2.1.0 |

This package is a development in progress. Pull requests are welcome.

Current assertions implemented so far are value eq, value deep eq, value null and value undefined assertions:

value.to.eq, value.to.deep.eq

Examples:

describe(`Scalar`, () => {
  it(`should equal value`, () => {
    expect(new y.Scalar('hello')).value.to.eq('hello')
    expect(new y.Scalar('hello')).value.to.eq(new y.Scalar('hello'))
    expect(new y.Scalar(null)).value.to.eq(null)
    expect(new y.Scalar(undefined)).value.to.eq(undefined)
    expect(new y.Scalar('')).value.to.eq('')
    expect(new y.Scalar('')).value.to.eq(new y.Scalar(''))
  })
})

describe(`Pair`, () => {
  it(`should equal value`, () => {
    expect(new y.Pair('hi', 0)).value.to.eq(0)
    expect(new y.Pair('', 0)).value.to.eq(new y.Scalar(0))
    expect(new y.Pair('hi', 1)).value.to.eq(1)
    expect(new y.Pair('apple', 1)).value.to.eq(new y.Scalar(1))
    expect(new y.Pair('apple', null)).value.to.eq(null)
    expect(new y.Pair('hi', null)).value.to.eq(new y.Scalar(null))
    expect(new y.Pair('hi', 'hello')).value.to.eq('hello')
    expect(new y.Pair('hi', 'hello')).value.to.eq(new y.Scalar('hello'))
    expect(new y.Pair('hi', '0')).value.to.eq('0')
    expect(new y.Pair('hi', '1')).value.to.eq(new y.Scalar('1'))
    expect(new y.Pair('hi', 'false')).value.to.eq(new y.Scalar('false'))
    expect(new y.Pair('hi', false)).value.to.eq(new y.Scalar(false))
    // expect(new y.Pair('hi', undefined)).value.to.eq(undefined)
    // expect(new y.Pair('hi')).value.to.eq(undefined)
  })
})

describe(`Map`, () => {
  it(`should equal value if same node`, () => {
    const node = new y.YAMLMap()
    expect(node).value.to.eq(node)
  })

  it(`should not equal value if different node`, () => {
    const node = new y.YAMLMap()
    const node2 = new y.YAMLMap()
    expect(node).value.not.to.eq(node2)
  })

  it(`should equal deep value`, () => {
    const node = new y.YAMLMap()
    node.set('hi', 'hello')
    expect(node).value.to.deep.eq({ hi: 'hello' })
    node.set('hi2', 'hello')
    expect(node).value.to.deep.eq({ hi: 'hello', hi2: 'hello' })
    node.delete('hi')
    expect(node).value.to.deep.eq({ hi2: 'hello' })
    node.delete('hi2')
    expect(node).value.to.deep.eq({})
    const node2 = new y.YAMLMap()
    node.set('hi', 'hello')
    node.set('hi2', 'hello')
    node2.set('hi', 'hello')
    node2.set('hi2', 'hello')
    expect(node).value.to.deep.eq(node2)
  })

  it(`should equal deep jsonified value`, () => {
    const node = new y.YAMLMap()
    const node2 = new y.YAMLMap()
    node.set('hi', 'hello')
    node.set('hi2', 'hello')
    node2.set('hi', 'hello')
    node2.set('hi2', 'hello')
    const res2 = node2.toJSON()
    expect(node).value.to.deep.eq(res2)
  })

  it(`should not equal value`, () => {
    const node = new y.YAMLMap()
    node.set('hi', 'hello')
    node.set('hi2', 'hello')
    expect(node).value.not.to.deep.eq({ hi: 'hello' })
    expect(node).value.not.to.deep.eq({ h2: 'hello' })
    expect(node).value.not.to.deep.eq({})
    expect(node).value.not.to.deep.eq(undefined)
    expect(node).value.not.to.deep.eq(null)
    expect(node).value.not.to.deep.eq('hello')
    expect(node).value.not.to.deep.eq('')
    expect(node).value.not.to.deep.eq(false)
    expect(node).value.not.to.deep.eq([])
  })
})

describe(`Seq`, () => {
  const node = new y.YAMLSeq()
  expect(node).value.to.deep.eq([])
  node.set(0, 'hello')
  expect(node).value.to.deep.eq(['hello'])
  node.set(0, 'hi')
  expect(node).value.to.deep.eq(['hi'])
  node.add('hello2')
  expect(node).value.to.deep.eq(['hi', 'hello2'])
  expect(node.items).to.have.lengthOf(2)
  node.items.length = 0
  expect(node).value.to.deep.eq([])
  expect(node).value.to.deep.eq(new y.YAMLSeq())
})

describe(`Document`, () => {
  it(`should equal value of document contents`, () => {
    expect(new y.Document(true)).value.to.eq(true)
    expect(new y.Document(false)).value.to.eq(false)
    expect(new y.Document(false)).value.to.eq(new y.Scalar(false))
    expect(new y.Document('hello')).value.to.eq('hello')
    expect(new y.Document('hello')).value.to.eq(new y.Scalar('hello'))
    expect(new y.Document(11)).value.to.eq(11)
    expect(new y.Document(11)).value.to.eq(new y.Scalar(11))
    expect(new y.Document({})).value.to.deep.eq({})
    expect(new y.Document({})).value.to.deep.eq(new y.YAMLMap())
    expect(new y.Document([])).value.to.deep.eq([])
    expect(new y.Document([])).value.to.deep.eq(new y.YAMLSeq())
    expect(new y.Document([''])).value.to.deep.eq([''])
  })
})

value.to.be.null

Examples:

describe(`Scalar`, () => {
  it(`should be null`, () => {
    expect(new y.Scalar(null)).value.to.be.null
  })
})

describe(`Document`, () => {
  it(`should be null`, () => {
    expect(new y.Document()).value.to.be.null
    expect(new y.Document(null)).value.to.be.null
  })
})

describe(`Pair`, () => {
  it(`should be null`, () => {
    expect(new y.Pair('hello', null)).value.to.be.null
  })
})

describe(`YAMLMap`, () => {
  it(`should not be null`, () => {
    expect(new y.YAMLMap()).value.not.to.be.null
  })
})

describe(`YAMLSeq`, () => {
  it(`should not be null`, () => {
    expect(new y.YAMLSeq()).value.not.to.be.null
  })
})

value.to.be.undefined

Examples:

describe(`Scalar`, () => {
  it(`should be undefined`, () => {
    expect(new y.Scalar(undefined)).value.to.be.undefined
    expect(new y.Scalar()).value.to.be.undefined
  })
})

describe(`Document`, () => {
  xit(`should be undefined`, () => {
    expect(new y.Document(undefined)).value.to.be.undefined
  })
})

describe(`Pair`, () => {
  it(`should be undefined`, () => {
    expect(new y.Pair('hello', null)).value.to.be.null
  })
})

describe(`YAMLMap`, () => {
  it(`should not be undefined`, () => {
    expect(new y.YAMLMap()).value.not.to.be.undefined
  })
})

describe(`YAMLSeq`, () => {
  it(`should not be undefined`, () => {
    expect(new y.YAMLSeq()).value.not.to.be.undefined
  })
})

TypeScript

TypeScript typings are available globally which will add a new Chai.Property value:

chai-value-property-assertion.png