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

feathers-tests-fake-app-users

v1.0.0

Published

Fake some feathers dependencies in service unit tests. Starter for your own customized fakes

Downloads

782

Readme

feathers-tests-fake-app-users

Fake some Feathers dependencies in service unit tests. Starter for your own customized fakes

Fake app and database services such as users.

Build Status Coverage Status Code Climate

Code Example

The following example is from test/example.js. It may be run with npm run test:only.

In this example we want to perform some unit tests on feathers-service-verify-reset's resend method, so we need to fake its Feathers dependencies app and users. We would be running integration tests if we used Feathers' actual app and users, and such tests would be more complicated.

const feathersFakes = require('feathers-tests-fake-app-user');
const verifyResetService = require('feathers-service-verify-reset').service;
const testUsersDb = [ // faked in-memory database
  { _id: 'a', email: 'a', isVerified: false, verifyToken: '000', verifyExpires: Date.now() + 5000 },
];

describe('verifyReset::resend', () => {
  var db, app, users, verifyReset;

  beforeEach(() => {
    db = clone(testUsersDb);
    app = feathersFakes.app(); // stub Feathers app
    users = feathersFakes.makeDbService(app, 'users', db); // mock users service
    app.use('/users', users);
    app.configure(verifyResetService());
    
    // Internally verifyResetService() attaches itself as a service with
    // app.use('/verifyReset/:action/:value', {...});
    // So now we get a handle to that service
    verifyReset = app.service('/verifyReset/:action/:value');
  });

  it('updates unverified user', (done) => {
    const email = 'a';
    verifyReset.create({ action: 'resend', value: email }, {}, (err, user) => {
      assert.strictEqual(err, null, 'err code set');

      // Check user record modified as expected
      assert.strictEqual(user.isVerified, false, 'isVerified not false');
      assert.isString(user.verifyToken, 'verifyToken not String');
      assert.equal(user.verifyToken.length, 30, 'verify token wrong length');

      // Check database record is identical
      assert.deepEqual(user, db[0]);

      done();
    });
  });
});

Motivation

It can be difficult to fake dependencies when running unit tests. This package provides fakes for the most common dependencies in a Feathers' project.

Installation

Install Nodejs.

Run npm install feathers-tests-fake-app-users --save-dev in your project folder.

You can then require the utilities.

/src on GitHub contains the ES6 source. It will run on Node 6+ without transpiling.

Running the Example

test/example.js is described above. It runs as part of the tests.

API Reference

See Code Example above.

The exports in src/index.js are fully documented.

Tests

npm test to run tests.

npm run cover to run tests plus coverage.

Contributors

License

MIT. See LICENSE.