Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chai-bookshelf

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chai-bookshelf

Chai assertions for bookshelf-based models

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

chai-bookshelf

Make assertions on your bookshelf.js models.

Build Status

Install

Install via npm: npm install chai-bookshelf

Note that it's handy to use the shortcut --save-dev: npm install --save-dev chai-bookshelf

Using

var chai = require('chai');
chai.use(require('chai-bookshelf'));

Assertions

Right now, only basic assertions on relationships are supported.

Relationships

Remove boiler plate from your code by making straightforward assertions

Supported Relationships include:

  • hasOne expect(ClassA).to.haveOne(ClassB)
  • hasMany expect(ClassA).to.haveMany(ClassB)
  • belongsTo expect(ClassA).to.belongTo(ClassB)
  • belongsToMany expect(ClassA).to.belongToMany(ClassB)
Basic Example

A basic example showing a test of a relationship

describe('User model', function() {
  var User
    , Thing
  ;

  beforeEach(function() {
    Thing = db.Model.extend({
      tableName: 'things'
    });

    User = db.Model.extend({
      things: function() {
        return this.hasMany(Thing);
      }
    });
  });

  describe('Relationships', function() {
    it('has many things', function() {
      expect(User).to.haveMany(Thing);
    })
  });
});
Specifying the attribute name example

By default, the assertion will use the singular form of the tablename. If the attribute is named something other than the target model's class (for example, to be plural) you will need to specify the name of the attribute that represents the relationship.

describe('User model', function() {
  var User
    , Thing
  ;

  beforeEach(function() {
    User = db.Model.extend({});

    Thing = db.Model.extend({
      owner: function() {
        this.belongsTo(User);
      }
    });
  });

  describe('Relationships', function() {
    it('has many things', function() {
      expect(Thing).to.belongTo(User, 'owner');
    })
  });
});

Keywords

FAQs

Package last updated on 17 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc