<commit_before>/**
 * import(s)
 */

var Vue = require('../../node_modules/vue/dist/vue')
var validator = require('../../index')
var wrapTemplate = require('./helper').wrapTemplate
var nextTick = Vue.util.nextTick


describe('required', function () {
  var vm, target

  function createInstance (inject, data) {
    var Validator = Vue.extend({
      template: wrapTemplate(inject),
      el: function () { return document.createElement('div') },
      data: data
    })
    return new Validator()
  }

  before(function () {
    Vue.use(validator)
  })


  describe('model data', function () {
    describe('set no empty', function () {
      beforeEach(function (done) {
        vm = createInstance(
          '<input type="text" v-model="msg" v-validate="required">',
          { msg: null }
        )
        target = vm._children[0]
        vm.msg = 'hello'
        vm._digest() // force update
        nextTick(done)
      })

      it('should be false', function () {
        expect(target.validation.msg.required).to.be(false)
      })
    })

    describe('set empty', function () {
      beforeEach(function (done) {
        vm = createInstance(
          '<input type="text" v-model="msg" v-validate="required">',
          { msg: 'hello' }
        )
        target = vm._children[0]
        vm.msg = ''
        vm._digest() // force update
        nextTick(done)
      })

      it('should be true', function () {
        expect(target.validation.msg.required).to.be(true)
      })
    })
  })


  describe('input `value` attribute', function () {
    describe('set no empty', function () {
      beforeEach(function (done) {
        vm = createInstance(
          '<input type="text" value="hello" v-model="msg" v-validate="required">',
          { msg: null }
        )
        target = vm._children[0]
        nextTick(done)
      })

      it('should be false', function () {
        expect(target.validation.msg.required).to.be(false)
      })
    })

    describe('set empty', function () {
      beforeEach(function (done) {
        vm = createInstance(
          '<input type="text" value="" v-model="msg" v-validate="required">',
          { msg: null }
        )
        target = vm._children[0]
        nextTick(done)
      })

      it('should be true', function () {
        expect(target.validation.msg.required).to.be(true)
      })
    })
  })
})<commit_msg>Update required validator spec<commit_after>/**
 * import(s)
 */

var Vue = require('../../node_modules/vue/dist/vue')
var validator = require('../../index')
var wrapTemplate = require('./helper').wrapTemplate
var nextTick = Vue.util.nextTick


describe('required', function () {
  var vm, target

  function createInstance (inject, data) {
    var Validator = Vue.extend({
      template: wrapTemplate(inject),
      el: function () {
        var el = document.createElement('div')
        document.body.appendChild(el)
        return el
      },
      data: data
    })
    return new Validator()
  }

  before(function () {
    Vue.config.async = false
    Vue.use(validator)
  })

  after(function () {
    Vue.config.async = true
  })


  describe('model data', function () {
    describe('set no empty', function () {
      beforeEach(function () {
        vm = createInstance(
          '<input type="text" v-model="msg" v-validate="required">',
          { msg: null }
        )
        target = vm._children[0]

        vm.msg = 'hello'
        vm._digest() // force update
      })

      it('should be false', function () {
        expect(target.validation.msg.required).to.be(false)
      })
    })

    describe('set empty', function () {
      beforeEach(function () {
        vm = createInstance(
          '<input type="text" v-model="msg" v-validate="required">',
          { msg: 'hello' }
        )
        target = vm._children[0]

        vm.msg = ''
        vm._digest() // force update
      })

      it('should be true', function () {
        expect(target.validation.msg.required).to.be(true)
      })
    })
  })


  describe('input `value` attribute', function () {
    describe('set no empty', function () {
      beforeEach(function () {
        vm = createInstance(
          '<input type="text" value="hello" v-model="msg" v-validate="required">',
          { msg: null }
        )
        target = vm._children[0]
      })

      it('should be false', function () {
        expect(target.validation.msg.required).to.be(false)
      })
    })

    describe('set empty', function () {
      beforeEach(function () {
        vm = createInstance(
          '<input type="text" value="" v-model="msg" v-validate="required">',
          { msg: null }
        )
        target = vm._children[0]
      })

      it('should be true', function () {
        expect(target.validation.msg.required).to.be(true)
      })
    })
  })
})
{'fraction_non_alphanumeric': 0.1609504132231405, 'fraction_numerical': 0.001652892561983471, 'mean_word_length': 2.1232258064516127, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6164222', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1416, 'n_words': 290}