grails - 测试 View 时如何模拟Asset-Pipeline taglib

标签 grails grails-3.1

我有一个测试,其中gsp使用Asset Pipeline标签assetPath,在grails 2中我没有问题,但是在grails 3中我得到了org.grails.taglib.GrailsTagException: [SOME_GSP.gsp:184] Error executing tag <g:form>: Error evaluating expression [assetPath(src: 'SOME_PDF.pdf')] on line [60]: No signature of method: SOME_GSP_gsp.assetPath() is applicable for argument types: (java.util.LinkedHashMap) values: [[src:SOME_PDF.pdf]]
Grails 3.1.6

测试文件示例:

@TestMixin(GroovyPageUnitTestMixin)
class SomeTests extends Specification {

    void "ssn is not returned to the SOME_GSP page"() {
        given:
        def cmd = new commandObject(SOME_FIELD: 'data')

        when:
        def renderedView = render(view: 'SOME_GSP', model: [cmd: cmd])

        then:
        assert !renderedView.contains('data')
    }
}

最佳答案

原来我需要模拟某些类:

@Mock([AssetsTagLib, AssetMethodTagLib, AssetProcessorService])

为了使类得以解决,我需要在build.gradle中添加一个testCompile依赖项。
testCompile "com.bertramlabs.plugins:asset-pipeline-grails:2.9.4"

关于grails - 测试 View 时如何模拟Asset-Pipeline taglib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38597805/

相关文章:

grails 错误 : grails. 验证。Validateable 不是 @grails.validation.Validateable 中的注释

api - 如何从Gmail导入联系人?

json - 将JSON从 Controller 转换为GSP格式化html标签

grails - 从 Controller 发送InputStream作为图像发送到gsp

grails - 适用于 Grails 3.x 的 Gradle DSL

grails - 在gradle中运行npm run watch命令

grails - 创建简单的插入表单时,Grails字段插件如何工作?

grails - Grails 2.4.4-将i18n设置为引用与/grails-app/i18n不同的目录

xml - GGTS中如何修改Tomcat相关的变化

grails - 将静态资源(css、js、htm)添加到 grails 3 应用程序