
Product
Unify Your Security Stack with Socket Basics
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.
chai-bookshelf
Advanced tools
Make assertions on your bookshelf.js models.
Install via npm: npm install chai-bookshelf
Note that it's handy to use the shortcut --save-dev: npm install --save-dev chai-bookshelf
var chai = require('chai');
chai.use(require('chai-bookshelf'));
Right now, only basic assertions on relationships are supported.
Remove boiler plate from your code by making straightforward assertions
Supported Relationships include:
expect(ClassA).to.haveOne(ClassB)
expect(ClassA).to.haveMany(ClassB)
expect(ClassA).to.belongTo(ClassB)
expect(ClassA).to.belongToMany(ClassB)
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);
})
});
});
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');
})
});
});
FAQs
Chai assertions for bookshelf-based models
The npm package chai-bookshelf receives a total of 5 weekly downloads. As such, chai-bookshelf popularity was classified as not popular.
We found that chai-bookshelf demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.
Product
Socket is launching experimental protection for the Hugging Face ecosystem, scanning for malware and malicious payload injections inside model files to prevent silent AI supply chain attacks.
Research
/Security News
The Socket Threat Research Team uncovered a coordinated campaign that floods the Chrome Web Store with 131 rebranded clones of a WhatsApp Web automation extension to spam Brazilian users.