Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"scripts": {
"build": "grunt build",
"release": "grunt release",
"publish:aws": "npm run test:tasks && grunt && grunt publish-to-aws",
"publish:aws": "grunt && npm run test:tasks && grunt publish-to-aws",
"format": "prettier --write '**/*.{js,css,json,md}' && eslint --fix .",
"lint": "npm run lint:eslint && npm run lint:prettier && npm run lint:types",
"lint:eslint": "eslint --max-warnings 0 .",
Expand Down
6 changes: 0 additions & 6 deletions spec/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@ module.exports = {
CompilerContext: true,
Handlebars: true,
handlebarsEnv: true,
shouldCompileTo: true,
shouldCompileToWithPartials: true,
shouldThrow: true,
expectTemplate: true,
compileWithPartials: true,
suite: true,
equal: true,
equals: true,
test: true,
testBoth: true,
raises: true,
Expand Down
102 changes: 50 additions & 52 deletions spec/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,102 +7,100 @@ describe('ast', function () {

describe('BlockStatement', function () {
it('should throw on mustache mismatch', function () {
shouldThrow(
function () {
handlebarsEnv.parse('\n {{#foo}}{{/bar}}');
},
Handlebars.Exception,
"foo doesn't match bar - 2:5"
);
expect(function () {
handlebarsEnv.parse('\n {{#foo}}{{/bar}}');
}).toThrow("foo doesn't match bar - 2:5");
});
});

describe('helpers', function () {
describe('#helperExpression', function () {
it('should handle mustache statements', function () {
equals(
expect(
AST.helpers.helperExpression({
type: 'MustacheStatement',
params: [],
hash: undefined,
}),
false
);
equals(
})
).toBe(false);
expect(
AST.helpers.helperExpression({
type: 'MustacheStatement',
params: [1],
hash: undefined,
}),
true
);
equals(
})
).toBe(true);
expect(
AST.helpers.helperExpression({
type: 'MustacheStatement',
params: [],
hash: {},
}),
true
);
})
).toBe(true);
});
it('should handle block statements', function () {
equals(
expect(
AST.helpers.helperExpression({
type: 'BlockStatement',
params: [],
hash: undefined,
}),
false
);
equals(
})
).toBe(false);
expect(
AST.helpers.helperExpression({
type: 'BlockStatement',
params: [1],
hash: undefined,
}),
true
);
equals(
})
).toBe(true);
expect(
AST.helpers.helperExpression({
type: 'BlockStatement',
params: [],
hash: {},
}),
true
);
})
).toBe(true);
});
it('should handle subexpressions', function () {
equals(AST.helpers.helperExpression({ type: 'SubExpression' }), true);
expect(AST.helpers.helperExpression({ type: 'SubExpression' })).toBe(
true
);
});
it('should work with non-helper nodes', function () {
equals(AST.helpers.helperExpression({ type: 'Program' }), false);
expect(AST.helpers.helperExpression({ type: 'Program' })).toBe(false);

equals(
AST.helpers.helperExpression({ type: 'PartialStatement' }),
expect(AST.helpers.helperExpression({ type: 'PartialStatement' })).toBe(
false
);
equals(
AST.helpers.helperExpression({ type: 'ContentStatement' }),
expect(AST.helpers.helperExpression({ type: 'ContentStatement' })).toBe(
false
);
equals(
AST.helpers.helperExpression({ type: 'CommentStatement' }),
expect(AST.helpers.helperExpression({ type: 'CommentStatement' })).toBe(
false
);

equals(AST.helpers.helperExpression({ type: 'PathExpression' }), false);
expect(AST.helpers.helperExpression({ type: 'PathExpression' })).toBe(
false
);

equals(AST.helpers.helperExpression({ type: 'StringLiteral' }), false);
equals(AST.helpers.helperExpression({ type: 'NumberLiteral' }), false);
equals(AST.helpers.helperExpression({ type: 'BooleanLiteral' }), false);
equals(
AST.helpers.helperExpression({ type: 'UndefinedLiteral' }),
expect(AST.helpers.helperExpression({ type: 'StringLiteral' })).toBe(
false
);
expect(AST.helpers.helperExpression({ type: 'NumberLiteral' })).toBe(
false
);
expect(AST.helpers.helperExpression({ type: 'BooleanLiteral' })).toBe(
false
);
expect(AST.helpers.helperExpression({ type: 'UndefinedLiteral' })).toBe(
false
);
expect(AST.helpers.helperExpression({ type: 'NullLiteral' })).toBe(
false
);
equals(AST.helpers.helperExpression({ type: 'NullLiteral' }), false);

equals(AST.helpers.helperExpression({ type: 'Hash' }), false);
equals(AST.helpers.helperExpression({ type: 'HashPair' }), false);
expect(AST.helpers.helperExpression({ type: 'Hash' })).toBe(false);
expect(AST.helpers.helperExpression({ type: 'HashPair' })).toBe(false);
});
});
});
Expand All @@ -111,10 +109,10 @@ describe('ast', function () {
var ast, body;

function testColumns(node, firstLine, lastLine, firstColumn, lastColumn) {
equals(node.loc.start.line, firstLine);
equals(node.loc.start.column, firstColumn);
equals(node.loc.end.line, lastLine);
equals(node.loc.end.column, lastColumn);
expect(node.loc.start.line).toBe(firstLine);
expect(node.loc.start.column).toBe(firstColumn);
expect(node.loc.end.line).toBe(lastLine);
expect(node.loc.end.column).toBe(lastColumn);
}

/* eslint-disable no-multi-spaces */
Expand Down
48 changes: 22 additions & 26 deletions spec/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,26 +381,26 @@ describe('blocks', function () {
var run;
expectTemplate('{{*decorator "success"}}')
.withDecorator('decorator', function (fn, props, container, options) {
equals(options.args[0], 'success');
expect(options.args[0]).toBe('success');
run = true;
return fn;
})
.withInput({ foo: 'success' })
.toCompileTo('');
equals(run, true);
expect(run).toBe(true);
});

it('should fail when accessing variables from root', function () {
var run;
expectTemplate('{{*decorator foo}}')
.withDecorator('decorator', function (fn, props, container, options) {
equals(options.args[0], undefined);
expect(options.args[0]).toBeUndefined();
run = true;
return fn;
})
.withInput({ foo: 'fail' })
.toCompileTo('');
equals(run, true);
expect(run).toBe(true);
});

describe('registration', function () {
Expand All @@ -411,9 +411,9 @@ describe('blocks', function () {
return 'fail';
});

equals(!!handlebarsEnv.decorators.foo, true);
expect(handlebarsEnv.decorators.foo).toBeTruthy();
handlebarsEnv.unregisterDecorator('foo');
equals(handlebarsEnv.decorators.foo, undefined);
expect(handlebarsEnv.decorators.foo).toBeUndefined();
});

it('allows multiple globals', function () {
Expand All @@ -424,32 +424,28 @@ describe('blocks', function () {
bar: function () {},
});

equals(!!handlebarsEnv.decorators.foo, true);
equals(!!handlebarsEnv.decorators.bar, true);
expect(handlebarsEnv.decorators.foo).toBeTruthy();
expect(handlebarsEnv.decorators.bar).toBeTruthy();
handlebarsEnv.unregisterDecorator('foo');
handlebarsEnv.unregisterDecorator('bar');
equals(handlebarsEnv.decorators.foo, undefined);
equals(handlebarsEnv.decorators.bar, undefined);
expect(handlebarsEnv.decorators.foo).toBeUndefined();
expect(handlebarsEnv.decorators.bar).toBeUndefined();
});

it('fails with multiple and args', function () {
shouldThrow(
function () {
handlebarsEnv.registerDecorator(
{
world: function () {
return 'world!';
},
testHelper: function () {
return 'found it!';
},
expect(function () {
handlebarsEnv.registerDecorator(
{
world: function () {
return 'world!';
},
{}
);
},
Error,
'Arg not supported with multiple decorators'
);
testHelper: function () {
return 'found it!';
},
},
{}
);
}).toThrow('Arg not supported with multiple decorators');
});
});
});
Expand Down
Loading