• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var chai = require('chai')
2var sinon = require('sinon')
3var sinonChai = require('sinon-chai')
4var expect = chai.expect
5chai.use(sinonChai)
6
7var fixer = require('../lib/fix')
8
9describe('fix', function () {
10  it('old fix method: ast hack and re-generate', function () {
11    expect(fixer.formatWhenFix('module.exports = {data: {a: 1}}')).
12      eql('module.exports = {\n    data: function () {\n        return { a: 1 };\n    }\n};')
13    expect(fixer.formatWhenFix('module.exports = {data: function () {return {a: 1}}}')).
14      eql('module.exports = {data: function () {return {a: 1}}}')
15  })
16
17  it('new fix method: loc-based hack', function () {
18    expect(fixer.fix('module.exports = {data: {a: 1}}')).
19      eql('module.exports = {data: function () {return {a: 1}}}')
20    expect(fixer.fix('module.exports = {data: function () {return {a: 1}}}')).
21      eql('module.exports = {data: function () {return {a: 1}}}')
22  })
23
24  it('fix code with multi lines', function () {
25    var result = fixer.fix('module.exports = {\n    data: {a: 1}}')
26    expect(result).eql('module.exports = {\n    data: function () {return {a: 1}}}')
27  })
28
29  it('fix code with other declarations', function () {
30    var result = fixer.fix('require("./b.wx")\n\nvar c = require("./lib/c")\n\nmodule.exports = {\n    data: {\n        text: "hello " + c.name\n    }\n};')
31    expect(result).eql('require("./b.wx")\n\nvar c = require("./lib/c")\n\nmodule.exports = {\n    data: function () {return {\n        text: "hello " + c.name\n    }}\n};')
32  })
33})
34