最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jasmine regexp using toContain function - Stack Overflow

programmeradmin2浏览0评论

I am using jasmine for testing JavaScript code.
I would like to check the content of render function in this way:

expect(this.view.el.innerHTML).toContain('<a href="#link">'+ 'regexp(any text)' +'</a>');

would be possible to pass some parameter as a regular expression?
If yes, how?

I am using jasmine for testing JavaScript code.
I would like to check the content of render function in this way:

expect(this.view.el.innerHTML).toContain('<a href="#link">'+ 'regexp(any text)' +'</a>');

would be possible to pass some parameter as a regular expression?
If yes, how?

Share Improve this question edited Jun 25, 2012 at 8:53 Lorraine Bernard asked Jun 25, 2012 at 8:06 Lorraine BernardLorraine Bernard 13.5k23 gold badges85 silver badges138 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

I think you would need to use the toMatch matcher which takes a regular expression (toContain expects a string parameter) and build your regular expression by concatenating the fixed and variable strings something like this:

var searchString = ...
expect(innerHTML).toMatch(new RegExp('<a href="#link">' + searchString + '</a>'));
发布评论

评论列表(0)

  1. 暂无评论