0

I am stuck with jasmine. I read/youtubed/googled but seems like I am on the wrong track.

Here is what I have so far. I've used protractor --elementExplorer to pull items from http://www.angular.io:

> element.all(by.css('.nav-link')).getText()
[ '', 'FEATURES', 'DOCS', 'RESOURCES', 'EVENTS', 'BLOG' ]

Here is my test:

import { ElementFinder, browser, by, element } from 'protractor';

describe('angulario homepage verify list', function () { //Suite in Jasmine
    it('should check top 5 link buttons', function () { // Test in Jasmine
        browser.get('https://angular.io'); // Entering application url in browser
        element.all(by.css('.nav-link')).getText()); {
            //expect statement goes here
        });
    });
});

i am trying to ensure 5 links on the center top are present and it appears the elementExplorer return an Array... How do i use it to create my locator and expect statements?

3
  • 1
    too much code (we're not code fixers) and not code formatted. please reduce scope and test smaller things and format your code – Michael Durrant Nov 23 '17 at 0:54
  • Have anyone found a solution to the above question? Please help, mee too stuck with the same problem.! – Mohammad Jiaullah Dec 3 '19 at 19:10
  • 1
    Did the advice in @alecxe's answer and the comments help you? If they didn't, you should ask a new question with your code, the HTML you are trying to check, and the error you are getting. – Kate Paulk Dec 3 '19 at 21:13
2

You may just use expect() and toEqual() matcher:

browser.get('https://angular.io'); 
expect(element.all(by.css('.nav-link')).getText()).toEqual([
    '', 'FEATURES', 'DOCS', 'RESOURCES', 'EVENTS', 'BLOG' 
]);
8
  • thanks, i tried this and i get this error on visua studio code : [ts] Argument of type 'string[]' is not assignable to parameter of type 'Expected<Promise<string>>'. Type 'string[]' is not assignable to type 'ObjectContaining<Promise<string>>'. Property 'jasmineMatches' is missing in type 'string[]'. do i assign this statement to a variable of type array[]? – user8816197 Nov 23 '17 at 17:25
  • this is what worked for me.... expect(element.all(by.css('.nav-link')).getText()).toBeTruthy([ '', 'FEATURES', 'DOCS', 'RESOURCES', 'EVENTS', 'BLOG' ]); – user8816197 Nov 23 '17 at 17:43
  • 1
    @user8816197 wait..no, the toBeTruth‌y() matcher is not actually gonna check the values of the texts - it is not an appropriate matcher in this case at all. You definitely need toEqual() to match the texts of the navigation links against your array of strings. – alecxe Nov 23 '17 at 18:20
  • @user8816197 regarding your error - it looks like you need to install proper typings for jasmine: github.com/DefinitelyTyped/DefinitelyTyped/issues/15215. – alecxe Nov 23 '17 at 18:21
  • could you please let me know what typings should i have... i will double check the conf file package.json as well... thanks in advance – user8816197 Nov 23 '17 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.