Giter Site home page Giter Site logo

sequelize-mock's Introduction

Mock Sequelize

A simple mocking interface designed for applications that use the sequelize.js library. This library was forked from https://github.com/BlinkUX/sequelize-mock This library is specifically for testing code relying on Sequelize models and is therefore a very bare library at the moment. The more complex functionality of Sequelize has not been included and the library will likely be fleshed out to include this functionality as needed.

Once Mock models have been defined, the mock models should be drop in replacements for your Sequelize model objects. Data is not retrieved from a database and instead is returned based on the setup of the mock objects, the query being made, and other applied or included information.

Example Usage

// Import the mock library
var SequelizeMock = require('mock-sequelize');

// Setup the mock database connection
var DBConnectionMock = new SequelizeMock();

// Define our Model
var UserMock = DBConnectionMock.define('users', {
		'email': '[email protected]',
		'username': 'blink',
		'picture': 'user-picture.jpg',
	}, {
		instanceMethods: {
			myTestFunc: function () {
				return 'Test User';
			},
		},
	});

// You can also associate mock models as well
var GroupMock = DBConnectionMock.define('groups', {
	'name': 'My Awesome Group',
});

UserMock.belongsTo(GroupMock);

// From there we can start using it like a normal model
UserMock.findOne({
	where: {
		username: 'my-user',
	},
}).then(function (user) {
	// `user` is a Sequelize Model-like object
	user.get('id');         // Auto-Incrementing ID available on all Models
	user.get('email');      // '[email protected]'; Pulled from default values
	user.get('username');  // 'my-user'; Pulled from the `where` in the query
	
	user.myTestFunc(); // Will return 'Test User' as defined above
	
	user.getGroup(); // Will return a `GroupMock` object
});

License

Licensed under the MIT license. Check the LICENSE file for more information.

sequelize-mock's People

Contributors

kevnz avatar loveandcoding avatar heynemann avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.