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

javascript - Expected '> ' to equal '> ' in jasmine - Stack Overflow

programmeradmin0浏览0评论

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.

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.

Share Improve this question edited Dec 25, 2015 at 16:45 jcubic asked Dec 25, 2015 at 16:38 jcubicjcubic 66.7k58 gold badges249 silver badges453 bronze badges 1
  • 1 can you provide a plete example to reproduce? – Daniel A. White Commented Dec 25, 2015 at 16:42
Add a ment  | 

1 Answer 1

Reset to default 13

&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!)

发布评论

评论列表(0)

  1. 暂无评论