Giter Site home page Giter Site logo

react-mock's Introduction

React Mock

styled with prettier Build Status Coverage Status Dev Dependencies Greenkeeper badge Donate

Mocking api calls from React Applications, using Pretenderjs and Fakerjs.

Simple Example usage

import { Server, Faker, uid } from 'react-mock'
const endPoint = '/api/v1/todos'

const todoSchema = {
  author: Faker.internet.email(),
  content: () => Faker.lorem.sentence(),
  createdAt: () => Faker.date.past()
}

const requestHandler = (request, generator) => {
  const todoList = generator.next(10, todoSchema);
  return [200, { 'Content-Type': 'application/json' }, JSON.stringify(todoList)];
}

Server.mockGet(endPoint, requestHandler)
Server.on() // to start mocking /api/v1/todos API
axios.get('/api/v1/todos').then(({ data }) => {
  // data is an array of 10 todo objects
})

Real use case

  • Suppose you want to simulate the fetching of 10 guides
    • You know the API Endpoint
    • You know the Format of each guide object
    • You know the Format of the Error response
// <app-root>/src/mock-server

import { Server, Faker, uid } from 'react-mock'

const apiRoute = '/api/v1/guides'
const requestHandler = (request, generator) => {
  const guides = generator.next(10); // @returns { <id1>: schema1, <id2>: schema2 }
  // const error = generator.error();
  return [200, { 'Content-Type': 'application/json' }, JSON.stringify(guides)];
}

const schema = {
  description: Faker.lorem.sentence(),
  createdAt: Faker.date.past(),
  favoredCount: Faker.random.number(),
  isPublic: random.boolean(),
  author: {
    id: uid.next(),
    name: Faker.name.findName(),
    picture: Faker.internet.avatar()
  }
};

const errorFormat = {
  message: Faker.lorem.sentence()
}

Server.mockGet(apiRoute, requestHandler, schema, errorFormat)

Server.on() // @returns Promise that resolves with null or rejects with Error
// Server.off()

react-mock's People

Contributors

fuse-mars avatar greenkeeper[bot] avatar nshimiye avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

react-mock's Issues

An in-range update of prettier is breaking the build 🚨

The devDependency prettier was updated from 1.18.0 to 1.18.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

prettier is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for 1.18.1

πŸ”— Changelog

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of @types/node is breaking the build 🚨

The devDependency @types/node was updated from 10.11.0 to 10.11.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@types/node is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of replace-in-file is breaking the build 🚨

The devDependency replace-in-file was updated from 3.4.3 to 3.4.4.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

replace-in-file is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 2 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of travis-deploy-once is breaking the build 🚨

The devDependency travis-deploy-once was updated from 5.0.8 to 5.0.9.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

travis-deploy-once is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v5.0.9

5.0.9 (2018-09-27)

Bug Fixes

  • use require.resolve to load babel preset (16292d3)
Commits

The new version differs by 2 commits.

  • 16292d3 fix: use require.resolve to load babel preset
  • 858d475 test: add babel-register.js to test coverage

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Generating deeper structures

When I'm trying to mock a structure like this:

generator.next(3, {key : Faker.lorem.word, inner: {prop1: Faker.lorem.word, prop2: Faker.lorem.sentence}})

the inner properties prop1 and prop2 do not get generated:

{"id":"0695987d-8dbc-4e1c-81a6-2de839b1eb03","key":"vel","inner":{}}

An in-range update of semantic-release is breaking the build 🚨

The devDependency semantic-release was updated from 15.12.3 to 15.12.4.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

semantic-release is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v15.12.4

15.12.4 (2018-11-30)

Bug Fixes

  • remove unnecessary branch parameter from push function (ffe1062)
Commits

The new version differs by 1 commits.

  • ffe1062 fix: remove unnecessary branch parameter from push function

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two-Factor Authentication, make configure the auth-only level is supported. semantic-release cannot publish with the default auth-and-writes level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

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.