mardi 2 février 2016

testing ui with jasmine

So I am new to jasmine and just wrote a couple of tests. I am not sure if the test I wrote to check wether the menu is hidden when a link in feedList is clicked is working. Maybe I am missing to put in a setTimeout. Check out the code:

/* TODO: Write a new test suite named "The menu" */

describe('The menu', function() {

    var bodyClass = function() {
        return $('body').hasClass('menu-hidden');
    };

    var menuIcon = $('.menu-icon-link');

    /* Determine wether body currently has menu-hidden class */
    var menuVisibility = bodyClass();

    /* TODO: Write a test that ensures the menu element is
     * hidden by default. You'll have to analyze the HTML and
     * the CSS to determine how we're performing the
     * hiding/showing of the menu element.
     */

    it('is hidden by default', function() {
        expect(menuVisibility).toBe(true);
    });
    /* Additional test to check wether menu is hidden
     * when a link in our feedList is clicked on
     */
    it('is hidden when link in feedList is clicked', function() {
        // get all links from feedlist and push them into an array
        var feedListLinks = [];
        $(".feed-list a").each(function(){ 
            feedListLinks.push($(this)); 
        });

        // try functionality for each of them
        feedListLinks.forEach(function(item){
            // open menu
            menuIcon.click();
            // click on item
            item.click();
            // check wether body has menu-hidden class
            menuVisibility = bodyClass();
            expect(menuVisibility).toBe(true);

        });

    });

Aucun commentaire:

Enregistrer un commentaire