Giter Site home page Giter Site logo

longuniquename / sequelize-mock Goto Github PK

View Code? Open in Web Editor NEW

This project forked from blinkux/sequelize-mock

0.0 2.0 0.0 210 KB

A simple mock interface specifically for testing code relying on Sequelize models

Home Page: https://sequelize-mock.readthedocs.io

License: MIT License

JavaScript 100.00%

sequelize-mock's Introduction

Sequelize Mock

npm CircleCI Coveralls MIT License Documentation Status

A mocking interface designed for testing code that uses Sequelize.

Documentation at sequelize-mock.readthedocs.io

Install

npm i sequelize-mock --save-dev

Getting Started

The Mock Models created with this library function as drop in replacements for your unit testing.

Start by importing the library

var SequelizeMock = require('sequelize-mock');

Initialize the library as you would Sequelize

var DBConnectionMock = new SequelizeMock();

Define your models

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

Once Mock models have been defined, you can use them as 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.

For example, your code might look something like this

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
});

Contributing

This library is under active development, so you should feel free to submit issues, questions, or pull requests.

License

Created by Blink UX and licensed under the MIT license. Check the LICENSE file for more information.

sequelize-mock's People

Contributors

loveandcoding avatar

Watchers

 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.