Skip to content
This repository was archived by the owner on Dec 25, 2017. It is now read-only.

Commit 3d9fe74

Browse files
committed
fix(override): occured error when using plugin
issues closes #92
1 parent 0e58704 commit 3d9fe74

File tree

7 files changed

+61
-26
lines changed

7 files changed

+61
-26
lines changed

config/karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = function (config) {
88

99
// frameworks to use
1010
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
11-
frameworks: ['mocha'],
11+
frameworks: ['mocha', 'sinon'],
1212

1313
// list of files / patterns to load in the browser
1414
files: [

dist/vue-validator.js

+13-21
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ return /******/ (function(modules) { // webpackBootstrap
8888

8989
var _directivesValidator2 = _interopRequireDefault(_directivesValidator);
9090

91-
var _validation = __webpack_require__(6);
92-
93-
var _validation2 = _interopRequireDefault(_validation);
94-
9591
/**
9692
* Install
9793
*
@@ -405,17 +401,15 @@ return /******/ (function(modules) { // webpackBootstrap
405401

406402
/***/ },
407403
/* 4 */
408-
/***/ function(module, exports, __webpack_require__) {
404+
/***/ function(module, exports) {
409405

410-
'use strict';
406+
"use strict";
411407

412-
Object.defineProperty(exports, '__esModule', {
408+
Object.defineProperty(exports, "__esModule", {
413409
value: true
414410
});
415411

416-
var _util = __webpack_require__(1);
417-
418-
exports['default'] = function (Vue) {
412+
exports["default"] = function (Vue) {
419413

420414
// override _init
421415
var init = Vue.prototype._init;
@@ -429,12 +423,12 @@ return /******/ (function(modules) { // webpackBootstrap
429423
// override _destroy
430424
var destroy = Vue.prototype._destroy;
431425
Vue.prototype._destroy = function () {
426+
destroy.apply(this, arguments);
432427
this._validatorMaps = null;
433-
destroy.call(this);
434428
};
435429
};
436430

437-
module.exports = exports['default'];
431+
module.exports = exports["default"];
438432

439433
/***/ },
440434
/* 5 */
@@ -462,12 +456,11 @@ return /******/ (function(modules) { // webpackBootstrap
462456
params: ['group'],
463457

464458
bind: function bind() {
465-
//console.log('validate:bind', this, this.arg)
466459
var vm = this.vm;
467460
var validatorName = vm.$options._validator;
468461
if (!validatorName) {
469462
// TODO: should be implemented error message
470-
_.warn('TODO: should be implemented error message');
463+
(0, _util.warn)('TODO: should be implemented error message');
471464
return;
472465
}
473466

@@ -484,7 +477,6 @@ return /******/ (function(modules) { // webpackBootstrap
484477
},
485478

486479
update: function update(value, old) {
487-
//console.log('validate:update', this.arg, value, old, typeof value, JSON.stringify(value))
488480
if (!value) {
489481
return;
490482
}
@@ -518,7 +510,6 @@ return /******/ (function(modules) { // webpackBootstrap
518510
},
519511

520512
unbind: function unbind() {
521-
//console.log('validate:unbind', this)
522513
if (this.validator && this.validation) {
523514
if (this.params.group) {
524515
this.validator.removeGroupValidation(this.params.group, this.validation);
@@ -604,7 +595,6 @@ return /******/ (function(modules) { // webpackBootstrap
604595
}, {
605596
key: 'listener',
606597
value: function listener(e) {
607-
//console.log('input event', e.type)
608598
if (e.relatedTarget && (e.relatedTarget.tagName === 'A' || e.relatedTarget.tagName === 'BUTTON')) {
609599
return;
610600
}
@@ -689,14 +679,14 @@ return /******/ (function(modules) { // webpackBootstrap
689679
bind: function bind() {
690680
if (!this.params.name) {
691681
// TODO: should be implemented validator:bind name params nothing error'
692-
_.warn('TODO: should be implemented validator:bind name params nothing error');
682+
(0, _util.warn)('TODO: should be implemented validator:bind name params nothing error');
693683
return;
694684
}
695685

696686
var validatorName = this.validatorName = '$' + this.params.name;
697687
if (!this.vm._validatorMaps) {
698688
// TODO: should be implemented error message'
699-
_.warn('TODO: should be implemented error message');
689+
(0, _util.warn)('TODO: should be implemented error message');
700690
return;
701691
}
702692

@@ -775,8 +765,10 @@ return /******/ (function(modules) { // webpackBootstrap
775765

776766
this.name = name;
777767
this.scope = {}; // TODO: change to Object.create(null)
778-
//this.scope = Object.create(null)
779-
//this.scope.a = 1
768+
/*
769+
this.scope = Object.create(null)
770+
this.scope.a = 1
771+
*/
780772

781773
this._dir = dir;
782774
this._validations = [];

dist/vue-validator.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@
2929
"karma-phantomjs-launcher": "^0.2.1",
3030
"karma-safari-launcher": "^0.1.1",
3131
"karma-sauce-launcher": "^0.2.14",
32+
"karma-sinon": "^1.0.4",
3233
"karma-sourcemap-loader": "^0.3.5",
3334
"karma-webpack": "^1.7.0",
3435
"mocha": "^2.3.1",
3536
"nightmare": "^2.0.5",
3637
"phantomjs": "^1.9.18",
3738
"power-assert": "^1.0.0",
39+
"sinon": "^1.17.2",
3840
"vue": "^1.0.8",
3941
"webpack": "^1.12.1",
4042
"webpack-dev-server": "^1.11.0"
@@ -68,8 +70,8 @@
6870
"lint": "eslint src test/specs",
6971
"mobile": "VUE_VALIDATOR_TYPE=sauce SAUCE=batch3 karma start config/karma.conf.js",
7072
"sauce": "npm run coolkids && npm run ie && npm run mobile",
71-
"unit": "karma start config/karma.conf.js",
7273
"test": "npm run ci",
74+
"unit": "karma start config/karma.conf.js",
7375
"watch": "babel src --out-dir lib --watch --source-maps-inline"
7476
}
7577
}

src/override.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function (Vue) {
1212
// override _destroy
1313
const destroy = Vue.prototype._destroy
1414
Vue.prototype._destroy = function () {
15+
destroy.apply(this, arguments)
1516
this._validatorMaps = null
16-
destroy.call(this)
1717
}
1818
}

test/specs/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import Vue from 'vue'
22
import VueValidator from '../../src/index'
33

4+
require('./validators')
5+
require('./override')
6+
47
Vue.use(VueValidator)
58

6-
require('./validators.js')
79
require('./asset')
810
require('./directives/validator')
911
require('./directives/validate')

test/specs/override.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import assert from 'power-assert'
2+
import override from '../../src/override'
3+
4+
5+
describe('override', () => {
6+
let Vue
7+
8+
beforeEach(() => {
9+
Vue = function Vue () {}
10+
Vue.prototype._init = (options) => {}
11+
Vue.prototype._destroy = () => {}
12+
})
13+
14+
15+
it('_init', () => {
16+
let options = { a: 1 }
17+
let spy = sinon.spy(Vue.prototype, '_init')
18+
spy.withArgs(options)
19+
20+
override(Vue)
21+
let vm = new Vue()
22+
vm._init(options)
23+
24+
assert(vm._validatorMaps !== undefined)
25+
assert(spy.withArgs(options).calledOnce)
26+
})
27+
28+
it('_destroy', () => {
29+
let spy = sinon.spy(Vue.prototype, '_destroy')
30+
spy.withArgs(false, false)
31+
32+
override(Vue)
33+
let vm = new Vue()
34+
vm._destroy(false, false)
35+
36+
assert(vm._validatorMaps === null)
37+
assert(spy.withArgs(false, false).calledOnce)
38+
})
39+
})

0 commit comments

Comments
 (0)