You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+1-3
Original file line number
Diff line number
Diff line change
@@ -25,8 +25,6 @@ Use the mixin function which returns a class with PropTypes and defaultProps log
25
25
constValidatingModel=propTypesMixin(Model);
26
26
```
27
27
28
-
If `process.env.NODE_ENV === 'production'`, PropTypes checking will be disabled.
29
-
30
28
Define your concrete model, and add `propTypes` and `defaultProps` static class attributes.
31
29
32
30
```javascript
@@ -44,7 +42,7 @@ Person.defaultProps = {
44
42
Person.modelName='Person';
45
43
```
46
44
47
-
The mixin adds a layer of logic on top of the Model static method `create` and the instance method `update`. When calling `create`, if you have defined `defaultProps`, it'll merge the defaults with the props you passed in. Then, if you've defined `Model.propTypes`, it'll validate the props. An error will be thrown if a prop is found to be invalid. The final props (that may have been merged with defaults) will be passed to the `create` method on the superclass you passed the mixin function.
45
+
The mixin adds a layer of logic on top of the Model static method `create` and the instance method `update`. When calling `create`, if you have defined `defaultProps`, it'll merge the defaults with the props you passed in. Then, if you've defined `Model.propTypes`, it'll validate the props. The final props (that may have been merged with defaults) will be passed to the `create` method on the superclass you passed the mixin function.
48
46
49
47
When you call the `modelInstance.update(attrObj)` instance method, the keys in `attrObj` will be checked against the corresponding `propTypes`, if they exist.
expect(consoleErrorSpy).toBeCalledWith('Warning: Failed prop type: The prop `name` is marked as required in `ModelWithMixin.create`, but its value is `undefined`.');
72
75
});
73
76
74
77
it('raises validation error on update correctly',()=>{
expect(consoleErrorSpy).toBeCalledWith('Warning: Failed prop type: Invalid prop `name` of type `number` supplied to `ModelWithMixin.update`, expected `string`.');
0 commit comments