const Vue = require('vue/dist/vue'); const VueHighlightJS = require('../index'); Vue.use(VueHighlightJS); test('highlighting pre-defined code', () => { const template = `
// Static source code
      function(test) {
          console.log(test)
      }
`; const vm = new Vue({ template, }).$mount(); const result = vm.$el.innerHTML; expect(result).toEqual(expect.stringContaining('')); expect(result).toEqual(expect.stringContaining('')); expect(result).toEqual(expect.stringContaining('')); expect(result).toEqual(expect.stringContaining('')); expect(result).toEqual(expect.stringContaining('')); }); describe('highlighting dynamic code', () => { let vm, result; beforeEach(() => { const template = `
`; vm = new Vue({ template, data: { sourcecode: 'const str = "This sourcecode will update dynamically"', }, }).$mount(); }); it('should highlight initial code', () => { result = vm.$el.innerHTML; expect(result).toEqual(expect.stringContaining('')); expect(result).toEqual(expect.stringContaining('')); }) it('should highlight code when updating variable', () => { vm.sourcecode = '123'; Vue.nextTick(function () { result = vm.$el.innerHTML; expect(result).toEqual('
123
'); }); }); it('should updated highlighted block when updating code without any content', () => { vm.sourcecode = ''; Vue.nextTick(function () { result = vm.$el.innerHTML; // console.log('result', result); expect(result).toEqual('
'); }); }); });