单元测试车把部分

ivp*_*ivp 5 javascript node.js handlebars.js jestjs

我想使用 Jest 对我的应用程序进行单元测试,Jest 使用 Handlebar 作为模板引擎。

我能够对 Handlebar 助手进行单元测试,但无法测试 Handlebar 部分。

当我尝试导入 spec.js 中的部分内容时,出现错误:

意外字符“#”(1:2)

下面是partial.handlerbars文件

{{#with (resource 'some_selector') }}
 <img alt="{{altText}}" src="{{image-url}}" />
{{/with}}
Run Code Online (Sandbox Code Playgroud)

下面是partial.spec.js

import partial from './partial.handlebars';
const Handlebars = require('handlebars');
describe('partial suite', ()=> {
  Handlebars.registerPartial('partial', partial);
  it('should always be true', ()=> {
    expect(true).toBe(true);
  })  
})
Run Code Online (Sandbox Code Playgroud)

下面是错误:

 D:/projects/src/components/partials/partial.handlebars: Unexpected character '#' (1:2)
  > 1 | {{#with (resource 'some_selector') }}
      |   ^
Run Code Online (Sandbox Code Playgroud)