【发布时间】:2018-06-26 13:45:21
【问题描述】:
在 Rails 项目中,我有一些包含 ERB 语法的 JavaScript 文件,即
// en_store.coffee.erb
EnStore =
activities:
title: 'Delete Note?'
image: '<%= asset_path("crm/sections/en/calendar.png") %>'
module.exports.EnStore = EnStore
还有测试:
// en_store.test.coffee
import { EnStore } from 'stores/en_store'
describe 'EN Store', () ->
// This test passes.
it 'should provide hard typed translation', () ->
expect(EnStore.activities.title).toBe('Delete Note?')
// This one fails as the EnStore.activities.image contains '<%= asset_path("crm/sections/en/calendar.png") %>' as a string and not the actual interpolated value.
it 'should provide asset path', () ->
expect(EnStore.activities.image).toBe('[This is not interpolated]')
尝试使用 Jest 对其进行测试会导致错误,因为 ERB 部分没有得到内插。在测试之外,这由 Webpack 通过rails-erb-loader 处理。我怎样才能让它与 Jest 一起工作?是否有任何现有的transform 包可以让我这样做?
或者是否有替代 Jest 的方法可以让我测试这些类型的文件?
【问题讨论】:
标签: ruby-on-rails webpack jestjs erb