Technology moves fast! ⚡ Don't get left behind.🚶 Subscribe to our mailing list to keep up with latest and greatest in open source projects! 🏆


Subscribe to our mailing list

mock

Simple web page mock middleware

Subscribe to updates I use mock


Statistics on mock

Number of watchers on Github 38
Number of open issues 0
Average time to close an issue 4 days
Main language JavaScript
Average time to merge a PR about 22 hours
Open pull requests 0+
Closed pull requests 3+
Last commit over 1 year ago
Repo Created over 4 years ago
Repo Last Updated over 1 year ago
Size 56 KB
Organization / Authorkoajs
Contributors5
Page Updated
Do you use mock? Leave a review!
View mock activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating mock for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

koa-mock

NPM version build status Test coverage David deps npm download

Web page mock middleware.


Features

  • Simple url and mock file mapping rules.
  • Support *.js, *.json and common datas.
  • Auto find all scenes and easy change it koa-mock

URL Mapping Rules

Use ?__scene[={scene}] to select mock scene, default scene is default.

Rules

{url}?__scene={scene} => {datadir}{url}/{scene}.js

Installation

$ npm install koa-mock

Quick start

Using nunjucks template engine for example:

  • NOTICE You must implement ctx.render(view, data) generator function first.
  • Use __scene[={scene}] querystring to enable mock and select one mock scene.

app.js

var path = require('path');
var nunjucks = require('nunjucks');
var koa = require('koa');
var mock = require('koa-mock');

var app = koa();
app.use(mock({
  datadir: path.join(__dirname, 'mocks')
}));

nunjucks.configure(path.join(__dirname, 'views'));

app.context.render = function* (view, data) {
  this.body = nunjucks.render(view, data);
};

app.listen(1984);

/mocks files

  • /mocks
    • default.js => {name: 'fengmk2', __view: 'home.html'}
    • /users
    • /1
      • default.js => {name: 'default-user', __view: 'profile.html'}
      • fengmk2.js => {name: 'fengmk2', __view: 'profile.html'}

/views files

  • /views
    • home.html => <p>welcome home, {{name}}</p>
    • profile.html => <p>profile, {{name}}</p>

Request the mock web page

$ curl http://localhost:1984/?__scene

Status: 200
<p>welcome home, fengmk2</p>

$ curl http://localhost:1984/users/1?__scene=default

Status: 200
<p>profile, default-user</p>

$ curl http://localhost:1984/users/1?__scene=fengmk2

Status: 200
<p>profile, fengmk2</p>

$ curl http://localhost:1984/

Status: 404
Not Found

License

MIT

mock questions on Stackoverflow (View All Questions)
  • On-the-fly creation of mock data using and injective method
  • How to tell the subject under test to use the mock instead of its own variable
  • Eclipse Scout Neon mock backend service
  • React js - How to mock Context when testing component
  • Why does Mockito test the mock instead of the object under test?
  • Using Mockito, how can I mock a return value of an instance method without having an instance of that class?
  • Accessing mock bluetooth GPS coordinates in cordova geolocation
  • mock paramiko.SSHClient().exec_command()
  • Angular2 mock an @Attribute("name") value of a constructor via jasmine beforeEachProviders
  • Dependency on mock method with PHPUnit
  • Jasmine & Angular: Injecting a service into a service mock
  • How to mock dependencies for unit tests with ES6 Modules
  • Mock ES6 dependencies when unit testing
  • mock java.nio.file.Paths.get do nothing but throw InvalidPathException
  • Google Mock: mock fstream object and control of execution in test
  • How do I mock angular's $http with sinon?
  • why mock data while testing?
  • jasmin: mock instance of a class
  • How to do a unit test for Http Get without using http backend, I want to mock the backend instead, I'm using jasmine and Angular 1?
  • Initialising mock objects - MockIto
  • Python Requests Mock doesn't catch Timeout exception
  • How do I setup a mock that dynamically returns results based on a parameter's value?
  • Mock an iterator five calls deep
  • Get reference to (Mock)ResourceResolverFactory
  • SoapUI: Create mock service with pass-through behavior for selected methods
  • Django mock message fails with module view
  • How to Mock an AutoMapper IMapper object in Web API Tests With StrcutureMap Dependency Injection?
  • Nullpointer in a @Mock (mocking final static Hashtable) with Powermock
  • What are the steps involved in Unit testing using Sling Mock
  • Angular add mock JSON Data
mock list of languages used
Other projects in JavaScript