2014-02-08 25 views
1

我正在寫一些茉莉花測試和toContain未在頁面上找到一個字符串。這裏是其中的一個:爲什麼茉莉花沒有找到我的網頁上的字符串

it('should contain Superhero', function() { 
    expect(el).toContain('Superhero'); 
    }); 

這裏是el的值,它是一個Jquery對象: enter image description here

而且,這裏是Karma錯誤:

Chrome 32.0.1700 (Mac OS X 10.8.5) marvelApp directives detail.window.directive should contain Superhero FAILED 
    TypeError: Object [object Object] has no method 'indexOf' 
     at null.<anonymous> (/Users/mhamm/Developer/marvel/test/mainCtrlSpec.js:61:20) 
Chrome 32.0.1700 (Mac OS X 10.8.5): Executed 1 of 0 (1 FAILED) ERROR (0 secs/10 mins 37.377 secs) 

爲什麼Jasmine沒有看到我的el中的超級英雄值?

+1

'[對象的對象]有沒有方法'indexOf'' – andlrc

回答

1

toContain預計,功能expect有一個字符串,而不是一個jQuery對象的方法:你爲什麼得到這個錯誤

it('should contain Superhero', function() { 
    expect(el.html()).toContain('Superhero'); 
    }); 

這就是:

[object Object] has no method 'indexOf'

0
it('should contain Superhero', function() { 
    expect(el.text()).toContain('Superhero'); 
});