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

assert-css

v1.0.2

Published

Assert that CSS is constructed properly

Downloads

4

Readme

assert-css

npm version

Assert that CSS is constructed properly.

Usage

import assertCss from 'assert-css';

describe('CSS generation', function () {
  it('should have the expected CSS', function () {
    assertCss('body { margin: 0; }').selector('body').includes('margin', 0);
  });
});

Chains

The project uses object chaining to complete assertions.

.selector()

The .selector() method has the following possible chains:

  • .selector().exists(), asserts that the selector is within the CSS.
  • .selector().not.exists(), asserts that the selector is not within the CSS.
  • .selector().includes(property), asserts that the given property exists within the selector.
  • .selector().not.includes(property), asserts that the given property does not exist within the selector.
  • .selector().includes(property, value), asserts that the property-value pair exists within the selector.
  • .selector().not.includes(property, value), asserts that the property-value pair does not exist within the selector.

The value within an includes() chain can be a custom validator function. This will pass in the resolved value as a string. Return true when a match is expected, false to throw an exception.

assertCss('body { margin: 0 1rem }')
  .selector('body')
  .includes('margin', (value) => value.includes('1rem')); // true

The given selector must be accurate to the expectation within the CSS. In other words:

assertCss('body[data-theme] { margin: 0 }').selector('body').exists(); // false
assertCss('body[data-theme] { margin: 0 }').selector('body').not.exists(); // true
assertCss('body[data-theme] { margin: 0 }').selector('body[data-theme]').exists(); // true

Also, note that this will not dive into at-rules. To check for existence within an at-rule, use .atRule() with the appropriate chain.

.atRule()

Similar .selector() in that this checks against the current CSS at-rule and its possible values with some differences:

  • .includes(value), completes a generic String.includes() against the current value. This is because various at-rule specifications do not have a repeatable construction. So (max-width: 800px) will match against max-width, 800 and 800px as examples. You may provide a function here instead for custom matching.
  • .selector(), is chainable off of .atRule() to check for specific selectors within an at-rule with all expected chains further.

See tests for possible example chains.