compiler.js 776 B

123456789101112131415161718192021222324252627282930
  1. // Only methods with no side effects are tested here
  2. describe('Compiler', function () {
  3. describe('.eval()', function () {
  4. var v = new Vue({
  5. data: {
  6. b: 1,
  7. c: {
  8. d: 2
  9. }
  10. }
  11. })
  12. it('should eval correct value', function () {
  13. var res = v.$compiler.eval('a {{b}} {{b + c.d}} c')
  14. assert.strictEqual(res, 'a 1 3 c')
  15. })
  16. it('should accept additional data', function () {
  17. var res = v.$compiler.eval('{{c.d}}', { c: { d: 3 } })
  18. assert.strictEqual(res, 3)
  19. res = v.$compiler.eval('{{c.d === 3 ? "a" : "b"}}', { c: { d: 3 } })
  20. assert.strictEqual(res, 'a')
  21. })
  22. })
  23. })