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

funcunit

v3.7.0

Published

<!-- @hide title

Downloads

2,090

Readme

FuncUnit

Build Status npm version Join our Slack

Write better tests, faster.

Note: FuncUnit Roadmap

The FuncUnit Getting Started guide is a quick walkthrough of creating and running a test.

Set up a test

QUnit provides the basic structure needed to write unit or functional tests.

Module

Modules are groups of tests with setup and teardown methods that run for each test.

module("Contacts", {
  // runs before each test
  setup: function(){
    // setup code
  },
  // runs after each test
  teardown: function(){
    // cleanup code
  }
});

Test

test("findOne", function(){
  // define a test
});

Assertions

test("counter", function() {
  ok(Conctacts.first().name, "there is a name property");
  equal(Contacts.counter(), 5, "there are 5 contacts");
});

Open a page

The following uses F.open( URL ) to open autocomplete.html before every test.

module("autosuggest", {
  setup: function() {
    F.open('autosuggest.html');
  }
});

Calling open on window will cause FuncUnit commands to operate on the current window. This is also the default if you don't open any page.

Query for elements

FuncUnit tests are written just like jQuery. F is a copy of the $ method. It is used to find elements in the page you're testing. Like $, FuncUnit methods are chainable on the results of F.

// grab the #description element, wait for it to be visible, type in it
F("#description").visible().type("Test Framework");

Simulate user actions

When you're testing a widget, you need to simulate the actions that user takes. FuncUnit uses the syn library to accurately simulate the correct low level events like mouseup and keypress for high level actions like click() and type(). The following shows how to simulate common user actions.

Click

// click a button
F('#submit_button').click();

Type

// type in an input
F('#task_name').type("Learn FuncUnit");

Drag

// drag a task item to the trash area
F('.task').drag(".trash");

Wait for page conditions

After a user action, your test page's event handlers run and the page is changed. Wait commands are used to wait for some page condition before continuing.

Waits are overloaded jQuery getter methods. F.fn.text( textVal, callback ) waits for an element's $.fn.text to match the textVal.

// wait for result to show "task complete"
F("#result").text("task complete");

Visible

// wait for first result to be visible
F('#autocomplete_results:first-child').visible();

Width

// after clicking a menu item, wait for its width to be 200px
F('#horizontal_menu_item').width(200);

Val

// wait for the input value
F('#language_input').val("JavaScript");

Size

// wait for number of matched elements
F('.contact').size(5);

There are many more waits possible.

After simulating an action and waiting for the page to change, you often want to get information about an element and run assertions. You can use jQuery getter methods in combination with QUnit assertions.

These methods (which return synchronous results) are used in callbacks that run after a wait method completes.

// wait until we have some results, then call the callback
F('.autocomplete_item').visible(function(){
  equal( F('.autocomplete_item').size(), 5, "there are 5 results");
});

These tests can be loaded in any browser. The app page opens in a separate window and results show up in the QUnit page.

test("JavaScript results", function(){
  F('input').click().type("JavaScript");

  // wait until we have some results
  F('.autocomplete_item').visible(function(){
    equal( F('.autocomplete_item').size(), 5, "there are 5 results");
  });
});