Blame view

node_modules/babelon/test/index.js 1.04 KB
ce4c83ff   wxy   初始提交
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  'use strict';
  let assert = require('assert');
  
  let babelon = require('../index.js');
  
  let locals = {
    faker: {
      name: {
        firstName: function(){ return 'First'; },
        lastName: function(){ return 'Last'; }
      }
    },
    user_id: 1,
    is_active: true,
    posts: [
      {id: 1},
      {id: 2},
      {id: 3}
    ],
    misc: {
      is_active: false,
      is_banned: false
    }
  };
  
  let tmplFile = `${__dirname}/example.babelon`;
  
  let obj = babelon.evalFile(tmplFile, locals);
  assert.equal(obj.user.id, 1);
  assert.equal(obj.user.name, 'First Last');
  assert.equal(obj.posts.length, 3);
  assert.equal(obj.is_banned, false);
  assert.equal(obj.is_active, true);
  
  obj = babelon.compileFile(tmplFile)(locals);
  assert.equal(obj.user.id, 1);
  assert.equal(obj.user.name, 'First Last');
  assert.equal(obj.posts.length, 3);
  assert.equal(obj.is_banned, false);
  assert.equal(obj.is_active, true);
  assert.equal(obj.addOne(1), 2);
  
  console.log('OK')
  
  // obj = babelon.evalFile(tmplFile, {faker: locals.faker, user_id: 1, posts: [{id: 1}], misc: {}, is_active: true});
  // console.log(obj);