【发布时间】:2015-04-11 19:30:54
【问题描述】:
我只是想调用一个函数,它从一个动态构建的继承类返回一个 Url 作为字符串:
class @Api
DEFAULT_API_VERSION: 'v2'
constructor: ->
@setVersion(@DEFAULT_API_VERSION)
return
setVersion: (version) ->
@version = version if version?
getVersion: ->
@version
baseUrl: ->
"http://api#{@getVersion()}.mysite.com/api/#{@getVersion()}/"
class @ApiArticle extends Api
constructor: ->
super
return
articlesUrl: ->
"#{@baseUrl}news/articles".toString()
这是父类中的测试 PASSING
it 'provides the baseUrl for Api calls', ->
api = new Api()
expect(api.baseUrl()).toEqual('http://apiv2.mysite.com/api/v2/')
这是我的测试,它失败
it 'returns all news articles url', ->
new ApiArticle()
url = api_article.articlesUrl()
expect(url).toEqual 'http://apiv2.mysite.com/api/v2/news/articles'
我从这个规范中得到的结果,它应该是一个字符串,但收到了这个:
Expected
'function () { return "http://api" + (this.getVersion()) + ".mysite.com/api/" + (this.getVersion()) + "/"; }news/articles'
to equal
'http://apiv2.mysite.com/api/v2/news/articles'.
有什么遗漏吗?我必须显式渲染/计算吗?
我对 JS 和 Coffee 很陌生。
谢谢!
【问题讨论】:
标签: javascript meteor coffeescript jasmine