diff --git a/packages/mock-addon-docs/stories/docs/installation-setup.mdx b/packages/mock-addon-docs/stories/docs/installation-setup.mdx
index f4a1941..2ebe6db 100644
--- a/packages/mock-addon-docs/stories/docs/installation-setup.mdx
+++ b/packages/mock-addon-docs/stories/docs/installation-setup.mdx
@@ -1,4 +1,3 @@
-
import { Meta } from '@storybook/addon-docs';
import LinkTo from '@storybook/addon-links/react';
import { Footer } from './footer';
@@ -22,6 +21,7 @@ import { Footer } from './footer';
```sh
npm i storybook-addon-mock -D
```
+
Using yarn
```sh
@@ -75,19 +75,17 @@ export default {
const Template = () => ;
export const FetchCall = Template.bind({});
-
```
Each mock object contains the following properties.
-| Property | Description | Required | Default |
-| ---------- | :------------------------------------------------------------------------------------------ | :------- | :------ |
-| `url` | Supports both **named parameters** (`/:foo/:bar`) and **query parameters**.(`/foo?bar=true`) | true | - |
-| `method` | Supports `GET`, `POST`, `PUT`, `PATCH` and `DELETE` methods. | true | - |
-| `status` | All possible [HTTP status codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status). | true | - |
-| `response` | A valid JSON format(Array or Object) or function.
Response function is a function that contains request object as a parameter. See the **Custom Response** section for example. | true | - |
-| `delay` | Emulate delayed response time in milliseconds. | - | `0` |
-
+| Property | Description | Required | Default |
+| ---------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :------- | :------ |
+| `url` | Supports both **named parameters** (`/:foo/:bar`) and **query parameters**.(`/foo?bar=true`) | true | - |
+| `method` | Supports `GET`, `POST`, `PUT`, `PATCH` and `DELETE` methods. | true | - |
+| `status` | All possible [HTTP status codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status). | true | - |
+| `response` | A value or a function that returns a value.
Response function is a function that contains request object as a parameter. See the **Custom Response** section for example. | true | - |
+| `delay` | Emulate delayed response time in milliseconds. | - | `0` |
diff --git a/packages/mock-addon/src/utils/validator.js b/packages/mock-addon/src/utils/validator.js
index 3e0be46..7662ade 100644
--- a/packages/mock-addon/src/utils/validator.js
+++ b/packages/mock-addon/src/utils/validator.js
@@ -22,12 +22,7 @@ export const schema = {
return value && statusCodes.indexOf(value.toString()) >= 0;
},
response: (value) => {
- return (
- (isObject(value) ||
- Array.isArray(value) ||
- typeof value === 'function') &&
- value !== null
- );
+ return typeof value !== 'undefined';
},
delay: (value) => {
return value ? typeof value === 'number' : true;
diff --git a/packages/mock-addon/src/utils/validator.test.js b/packages/mock-addon/src/utils/validator.test.js
index e2eb4d8..d0c320d 100644
--- a/packages/mock-addon/src/utils/validator.test.js
+++ b/packages/mock-addon/src/utils/validator.test.js
@@ -204,7 +204,7 @@ describe('Validator', () => {
expect(actual).toEqual([]);
});
- it('should return not valid response error if response is a string', () => {
+ it('should return empty error if response is a string', () => {
const mock = {
url: 'https://jsonplaceholder.typicode.com/todos/:id',
method: 'GET',
@@ -213,10 +213,10 @@ describe('Validator', () => {
response: 'string',
};
const actual = validate(mock, schema);
- expect(actual).toEqual(['response: "string" is not valid.']);
+ expect(actual).toEqual([]);
});
- it('should return not valid response error if response is null', () => {
+ it('should return empty error if response is null', () => {
const mock = {
url: 'https://jsonplaceholder.typicode.com/todos/:id',
method: 'GET',
@@ -225,7 +225,19 @@ describe('Validator', () => {
response: null,
};
const actual = validate(mock, schema);
- expect(actual).toEqual(['response: null is not valid.']);
+ expect(actual).toEqual([]);
+ });
+
+ it('should return not valid response error if response is undefined', () => {
+ const mock = {
+ url: 'https://jsonplaceholder.typicode.com/todos/:id',
+ method: 'GET',
+ status: 200,
+ delay: 0,
+ response: undefined,
+ };
+ const actual = validate(mock, schema);
+ expect(actual).toEqual(['response: undefined is not valid.']);
});
});
describe('validate delay', () => {