Improve tests
This commit is contained in:
@@ -5,8 +5,6 @@ import {
|
||||
HandlebarsTemplateDelegate,
|
||||
HandlebarsTemplates,
|
||||
TemplateSpecification,
|
||||
CompileOptions,
|
||||
PrecompileOptions,
|
||||
RuntimeOptions,
|
||||
KnownHelpers,
|
||||
BuiltinHelperName,
|
||||
@@ -335,22 +333,22 @@ describe('Handlebars.create', () => {
|
||||
// Handlebars.parse / parseWithoutProcessing
|
||||
// ---------------------------------------------------------------------------
|
||||
describe('Handlebars.parse', () => {
|
||||
test('works without options', () => {
|
||||
expect(Handlebars.parse('{{name}}')).type.not.toRaiseError();
|
||||
test('returns hbs.AST.Program', () => {
|
||||
expect(Handlebars.parse('{{name}}')).type.toBe<hbs.AST.Program>();
|
||||
});
|
||||
|
||||
test('accepts ParseOptions', () => {
|
||||
expect(
|
||||
Handlebars.parse('{{name}}', { srcName: 'test.hbs' })
|
||||
).type.not.toRaiseError();
|
||||
).type.toBe<hbs.AST.Program>();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Handlebars.parseWithoutProcessing', () => {
|
||||
test('returns AST.Program', () => {
|
||||
test('returns hbs.AST.Program', () => {
|
||||
expect(
|
||||
Handlebars.parseWithoutProcessing('{{name}}')
|
||||
).type.not.toRaiseError();
|
||||
).type.toBe<hbs.AST.Program>();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -387,33 +385,11 @@ describe('RuntimeOptions', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// CompileOptions
|
||||
// ---------------------------------------------------------------------------
|
||||
describe('CompileOptions', () => {
|
||||
test('accepts all fields', () => {
|
||||
expect(
|
||||
Handlebars.compile('test', {
|
||||
data: true,
|
||||
compat: true,
|
||||
knownHelpers: { each: true },
|
||||
knownHelpersOnly: true,
|
||||
noEscape: true,
|
||||
strict: true,
|
||||
assumeObjects: true,
|
||||
preventIndent: true,
|
||||
ignoreStandalone: true,
|
||||
explicitPartialContext: true,
|
||||
})
|
||||
).type.not.toRaiseError();
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// HandlebarsTemplateDelegate generic
|
||||
// ---------------------------------------------------------------------------
|
||||
describe('HandlebarsTemplateDelegate generic', () => {
|
||||
test('enforces context type', () => {
|
||||
test('accepts matching context type', () => {
|
||||
const template: HandlebarsTemplateDelegate<{ name: string }> =
|
||||
Handlebars.compile<{ name: string }>('{{name}}');
|
||||
expect(template({ name: 'test' })).type.toBe<string>();
|
||||
@@ -449,33 +425,6 @@ describe('Handlebars.VM.resolvePartial', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ICompiler interface
|
||||
// ---------------------------------------------------------------------------
|
||||
describe('Handlebars.ICompiler', () => {
|
||||
test('has all visitor methods', () => {
|
||||
const compiler = {} as Handlebars.ICompiler;
|
||||
expect(compiler.accept).type.not.toRaiseError();
|
||||
expect(compiler.Program).type.not.toRaiseError();
|
||||
expect(compiler.BlockStatement).type.not.toRaiseError();
|
||||
expect(compiler.PartialStatement).type.not.toRaiseError();
|
||||
expect(compiler.PartialBlockStatement).type.not.toRaiseError();
|
||||
expect(compiler.DecoratorBlock).type.not.toRaiseError();
|
||||
expect(compiler.Decorator).type.not.toRaiseError();
|
||||
expect(compiler.MustacheStatement).type.not.toRaiseError();
|
||||
expect(compiler.ContentStatement).type.not.toRaiseError();
|
||||
expect(compiler.CommentStatement).type.not.toRaiseError();
|
||||
expect(compiler.SubExpression).type.not.toRaiseError();
|
||||
expect(compiler.PathExpression).type.not.toRaiseError();
|
||||
expect(compiler.StringLiteral).type.not.toRaiseError();
|
||||
expect(compiler.NumberLiteral).type.not.toRaiseError();
|
||||
expect(compiler.BooleanLiteral).type.not.toRaiseError();
|
||||
expect(compiler.UndefinedLiteral).type.not.toRaiseError();
|
||||
expect(compiler.NullLiteral).type.not.toRaiseError();
|
||||
expect(compiler.Hash).type.not.toRaiseError();
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Visitor class
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -483,12 +432,6 @@ describe('Handlebars.Visitor', () => {
|
||||
test('implements ICompiler', () => {
|
||||
expect<Handlebars.Visitor>().type.toBeAssignableTo<Handlebars.ICompiler>();
|
||||
});
|
||||
|
||||
test('has acceptKey and acceptArray methods', () => {
|
||||
const visitor = new Handlebars.Visitor();
|
||||
expect(visitor.acceptKey).type.not.toRaiseError();
|
||||
expect(visitor.acceptArray).type.not.toRaiseError();
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -541,9 +484,11 @@ describe('top-level exports', () => {
|
||||
expect<CustomHelperName>().type.toBe<string>();
|
||||
});
|
||||
|
||||
test('KnownHelpers uses BuiltinHelperName and CustomHelperName', () => {
|
||||
const helpers: KnownHelpers = { each: true, myCustom: true };
|
||||
expect(helpers).type.not.toRaiseError();
|
||||
test('KnownHelpers accepts builtin and custom helper names', () => {
|
||||
expect<{
|
||||
each: true;
|
||||
myCustom: true;
|
||||
}>().type.toBeAssignableTo<KnownHelpers>();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -558,20 +503,6 @@ describe('hbs namespace', () => {
|
||||
test('hbs.Utils aliases typeof Handlebars.Utils', () => {
|
||||
expect<hbs.Utils>().type.toBe<typeof Handlebars.Utils>();
|
||||
});
|
||||
|
||||
test('AST types are accessible', () => {
|
||||
const node = {} as hbs.AST.MustacheStatement;
|
||||
expect(node.type).type.not.toRaiseError();
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Handlebars.AST
|
||||
// ---------------------------------------------------------------------------
|
||||
describe('Handlebars.AST', () => {
|
||||
test('helpers is accessible', () => {
|
||||
expect(Handlebars.AST.helpers).type.not.toRaiseError();
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
{
|
||||
"extends": "@definitelytyped/dtslint/dtslint.json",
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": false,
|
||||
"array-type": false,
|
||||
"arrow-return-shorthand": false,
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"eofline": false,
|
||||
"export-just-namespace": false,
|
||||
"import-spacing": false,
|
||||
"interface-name": false,
|
||||
"interface-over-type-literal": false,
|
||||
"jsdoc-format": false,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"new-parens": false,
|
||||
"no-any-union": false,
|
||||
"no-boolean-literal-compare": false,
|
||||
"no-conditional-assignment": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-construct": false,
|
||||
"no-declare-current-package": false,
|
||||
"no-duplicate-imports": false,
|
||||
"no-duplicate-variable": false,
|
||||
"no-empty-interface": false,
|
||||
"no-for-in-array": false,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": false,
|
||||
"no-irregular-whitespace": false,
|
||||
"no-mergeable-namespace": false,
|
||||
"no-misused-new": false,
|
||||
"no-namespace": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-padding": false,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-redundant-jsdoc-2": false,
|
||||
"no-redundant-undefined": false,
|
||||
"no-reference-import": false,
|
||||
"no-relative-import-in-test": false,
|
||||
"no-self-import": false,
|
||||
"no-single-declare-module": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-callback-wrapper": false,
|
||||
"no-unnecessary-class": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-unnecessary-type-assertion": false,
|
||||
"no-useless-files": false,
|
||||
"no-var-keyword": false,
|
||||
"no-var-requires": false,
|
||||
"no-void-expression": false,
|
||||
"no-trailing-whitespace": false,
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-line": false,
|
||||
"one-variable-per-declaration": false,
|
||||
"only-arrow-functions": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"prefer-const": false,
|
||||
"prefer-declare-function": false,
|
||||
"prefer-for-of": false,
|
||||
"prefer-method-signature": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user