Repository: baianat/vee-validate
Pull request #2129 (2019-06-13 09:56:36)

Create a empty messages object when not exists
Fix:
If you set a custom message with setMessage and no message object exists you get an error

codecov[bot]: # [Codecov](https://codecov.io/gh/baianat/vee-validate/pull/2129?src=pr&el=h1) Report
> Merging [#2129](https://codecov.io/gh/baianat/vee-validate/pull/2129?src=pr&el=desc) into [master](https://codecov.io/gh/baianat/vee-validate/commit/bd5d43e45e1a42b3d3a8679bb5770a459dbb3c2f?src=pr&el=desc) will **decrease** coverage by `0.03%`.
> The diff coverage is `50%`.

[![Impacted file tree graph](https://codecov.io/gh/baianat/vee-validate/pull/2129/graphs/tree.svg?width=650&token=XFzlvHKFP5&height=150&src=pr)](https://codecov.io/gh/baianat/vee-validate/pull/2129?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #2129      +/-   ##
==========================================
- Coverage   95.59%   95.55%   -0.04%     
==========================================
  Files          62       62              
  Lines        2382     2384       +2     
  Branches      749      750       +1     
==========================================
+ Hits         2277     2278       +1     
- Misses         94       95       +1     
  Partials       11       11
```


| [Impacted Files](https://codecov.io/gh/baianat/vee-validate/pull/2129?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/localization/default.js](https://codecov.io/gh/baianat/vee-validate/pull/2129/diff?src=pr&el=tree#diff-c3JjL2xvY2FsaXphdGlvbi9kZWZhdWx0Lmpz) | `98.38% <50%> (-1.62%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/baianat/vee-validate/pull/2129?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/baianat/vee-validate/pull/2129?src=pr&el=footer). Last update [bd5d43e...7ac51be](https://codecov.io/gh/baianat/vee-validate/pull/2129?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/src/localization/default.js b/src/localization/default.js
index 94333026..174d28b4 100644
--- a/src/localization/default.js
+++ b/src/localization/default.js
@@ -111,6 +111,10 @@ export default class Dictionary implements IDictionary {
         attributes: {}
       };
     }
+    
+    if (!this.container[locale].messages) {
+      this.container[locale].messages = {}
+    }
 
     this.container[locale].messages[key] = message;
   }
diff --git a/types/vee-validate.d.ts b/types/vee-validate.d.ts
index 8f4ad33f..8ef98926 100644
--- a/types/vee-validate.d.ts
+++ b/types/vee-validate.d.ts
@@ -478,8 +478,10 @@ export class Validator {
 export class ExtendOptions {
     hasTarget?: boolean;
     paramNames?: string[];
-    computesRequired?: Boolean
-    initial?: Boolean
+    computesRequired?: boolean;
+    initial?: boolean;
+    immediate?: boolean;
+    isDate?: boolean;
 }
 
 /**
diff --git a/types/vue.d.ts b/types/vue.d.ts
index f6838cf1..8eb4116d 100644
--- a/types/vue.d.ts
+++ b/types/vue.d.ts
@@ -3,7 +3,7 @@
  */
 
 import Vue, { ComponentOptions } from 'vue';
-import { ErrorBag, FieldFlagsBag, Validator, VeeValidateComponentOptions } from './vee-validate.d';
+import { Validator, VeeValidateComponentOptions } from './vee-validate.d';
 
 declare module 'vue/types/options' {
   interface ComponentOptions<V extends Vue> {


Test patch:
diff --git a/tests/unit/localization/default.js b/tests/unit/localization/default.js
index c4700a7c..9df5c548 100644
--- a/tests/unit/localization/default.js
+++ b/tests/unit/localization/default.js
@@ -70,6 +70,17 @@ test('can set messages', () => {
   expect(dict.getMessage('en', 'winter')).toBe('Winter is coming');
 });
 
+test('can set messages when no messages present', () => {
+  const dict = new Dictionary();
+  dict.merge({
+    'nl': {}
+  });
+
+  dict.setMessage('nl', 'winter', 'De winter komt er aan');
+
+  expect(dict.getMessage('nl', 'winter')).toBe('De winter komt er aan');
+});
+
 test('can set attributes', () => {
   const dict = new Dictionary({
     en: {