Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expected '> ' to equal '> ' in jasmine

I'm testing jQuery terminal and I got error:

Expected '> ' to equal '> '.

when testing:

$(function() {
    describe('Terminal plugin', function() {
        describe('terminal create terminal destroy', function() {
            var term = $('<div id="term"></div>').appendTo('body').terminal();
            it('should have default prompt', function() {
                var prompt = term.find('.prompt');
                expect(prompt.html()).toEqual("<span>&gt;&nbsp;</span>");
                expect(prompt.text()).toEqual('> ');
            });
        });
    });
});

they are same value I just copy it into console and replace to equal by == or === and it return true.

like image 332
jcubic Avatar asked Dec 25 '15 16:12

jcubic


1 Answers

&nbsp; is not a "regular" space, so "&gt;&nbsp;" and "> " are not equivalent.

Instead, try expect(prompt.text()).toEqual('>\xA0'), that being the hex code for a non-breaking space (it's a better idea than putting an actual non-breaking space in there!)

like image 61
Niet the Dark Absol Avatar answered Oct 01 '22 15:10

Niet the Dark Absol