New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Official `length` workaround doesn't work #30

Closed
endash opened this Issue Apr 17, 2013 · 16 comments

Comments

Projects
None yet
10 participants
@endash

endash commented Apr 17, 2013

About to dig deeper into this, but the be.of.length(x) workaround for have.length(x) no longer seems to work.

I just cloned fresh, npm installed and added a single test for

$('<div></div>').should.be.of.length(1);

And get the following failure:

TypeError: Property 'length' of object function (selector) {
    var obj = flag(this, 'object');
    if (obj instanceof $) {
      this.assert(
          obj.is(selector)
        , 'expected #{this} to be #{exp}'
        , 'expected #{this} not to be #{exp}'
        , selector
      );
    } else {
      _super.apply(this, arguments);
    }
  } is not a function
at Context.<anonymous> (file://localhost/Users/chris/dev/chai-jquery/test/chai-jquery-spec.js:604:37)
at Test.Runnable.run (file://localhost/Users/chris/dev/chai-jquery/node_modules/mocha/mocha.js:4039:32)
at Runner.runTest (file://localhost/Users/chris/dev/chai-jquery/node_modules/mocha/mocha.js:4404:10)
at file://localhost/Users/chris/dev/chai-jquery/node_modules/mocha/mocha.js:4450:12
at next (file://localhost/Users/chris/dev/chai-jquery/node_modules/mocha/mocha.js:4330:14)
at file://localhost/Users/chris/dev/chai-jquery/node_modules/mocha/mocha.js:4339:7
at next (file://localhost/Users/chris/dev/chai-jquery/node_modules/mocha/mocha.js:4287:23)
at file://localhost/Users/chris/dev/chai-jquery/node_modules/mocha/mocha.js:4307:5
at timeslice (file://localhost/Users/chris/dev/chai-jquery/node_modules/mocha/mocha.js:5279:29)

I get a different error in Safari:

'1' is not a function (evaluating 'subject.should.be.of.length(1)')

I suppose it's possible there's something wrong with my setup, but I don't see what it could be...

@endash

This comment has been minimized.

Show comment
Hide comment
@endash

endash Apr 17, 2013

New workaround, for the terminal variation of length: should.have.lengthOf(n)

FWIW the function it's complaining about and spitting out in the error message is the be method overwritten by chai-jquery, not a new addition at all. It is perplexing.

endash commented Apr 17, 2013

New workaround, for the terminal variation of length: should.have.lengthOf(n)

FWIW the function it's complaining about and spitting out in the error message is the be method overwritten by chai-jquery, not a new addition at all. It is perplexing.

@endash

This comment has been minimized.

Show comment
Hide comment
@endash

endash Apr 17, 2013

Rolling back chai to 1.4.0 has no effect... I'm at a loss to explain why the workaround would have ever worked, given that be is also overridden to be a function, just like have.

endash commented Apr 17, 2013

Rolling back chai to 1.4.0 has no effect... I'm at a loss to explain why the workaround would have ever worked, given that be is also overridden to be a function, just like have.

@jfirebaugh

This comment has been minimized.

Show comment
Hide comment
@jfirebaugh

jfirebaugh Apr 17, 2013

Member

It may well be that it never did work. I should've added it to the test suite when it was first proposed, but neglected to.

Member

jfirebaugh commented Apr 17, 2013

It may well be that it never did work. I should've added it to the test suite when it was first proposed, but neglected to.

@nackjicholson

This comment has been minimized.

Show comment
Hide comment
@nackjicholson

nackjicholson Sep 9, 2013

Only real work around my team has found is to not use length at all. And instead do expect(selection.length).to.equal(number);

nackjicholson commented Sep 9, 2013

Only real work around my team has found is to not use length at all. And instead do expect(selection.length).to.equal(number);

@alexstrat

This comment has been minimized.

Show comment
Hide comment
@alexstrat

alexstrat Oct 25, 2013

chai-jquery's have should maybe be renamed in something that does not interfere with chai's original have ?

alexstrat commented Oct 25, 2013

chai-jquery's have should maybe be renamed in something that does not interfere with chai's original have ?

@fizker

This comment has been minimized.

Show comment
Hide comment
@fizker

fizker Dec 6, 2013

@nackjicholson I prefer expect(selection).to.have.property('length', number); over expect(selection.length).to.equal(number);.

I find that version way more readable in case of failure (Failure will read expected ... to have a property 'length' of x, but got y instead of expected x to be y.

fizker commented Dec 6, 2013

@nackjicholson I prefer expect(selection).to.have.property('length', number); over expect(selection.length).to.equal(number);.

I find that version way more readable in case of failure (Failure will read expected ... to have a property 'length' of x, but got y instead of expected x to be y.

@jedmao

This comment has been minimized.

Show comment
Hide comment
@jedmao

jedmao Mar 3, 2014

I'm getting the same error with:

expect($('.foo')).to.have('h1');

TypeError: '[object Object]' is not a function (evaluating 'expect($('.foo')).to.have('h1')')

jedmao commented Mar 3, 2014

I'm getting the same error with:

expect($('.foo')).to.have('h1');

TypeError: '[object Object]' is not a function (evaluating 'expect($('.foo')).to.have('h1')')

@mattfysh

This comment has been minimized.

Show comment
Hide comment
@mattfysh

mattfysh Mar 28, 2014

I ended up opting for:

expect($('body')).with.length(1);

mattfysh commented Mar 28, 2014

I ended up opting for:

expect($('body')).with.length(1);
@jedmao

This comment has been minimized.

Show comment
Hide comment
@jedmao

jedmao Mar 28, 2014

My issue was actually an issue with installing Chai Jquery into Karma. Now, my original expression works just fine.

jedmao commented Mar 28, 2014

My issue was actually an issue with installing Chai Jquery into Karma. Now, my original expression works just fine.

@marcandre

This comment has been minimized.

Show comment
Hide comment
@marcandre

marcandre Mar 31, 2014

with works fine.
Please fix the doc!

marcandre commented Mar 31, 2014

with works fine.
Please fix the doc!

@gumaflux

This comment has been minimized.

Show comment
Hide comment
@gumaflux

gumaflux Apr 17, 2014

@jedmao: what exactly was the issue having the same prob with a mocha setup

gumaflux commented Apr 17, 2014

@jedmao: what exactly was the issue having the same prob with a mocha setup

@jedmao

This comment has been minimized.

Show comment
Hide comment
@jedmao

jedmao Apr 17, 2014

@gumaflux my issue was with both syntaxes. The first isn't officially supported, so that shouldn't be a surprise:

expect(selection).to.have.length(2);

The second, however, was explicitly stated in the documentation as a workaround:

expect(selection).to.be.of.length(2);

This also doesn't work. The way I'm doing it now is pretty much as @nackjicholson has stated:

expect(selection.length).to.eq(2);

This is the only way I've gotten it to work. I'm sure the other ways expressed above work also, but I'm not interested in those syntaxes.

BTW @jfirebaugh, I can confirm that this workaround does, in fact, NOT work! I would love it if it did :)

jedmao commented Apr 17, 2014

@gumaflux my issue was with both syntaxes. The first isn't officially supported, so that shouldn't be a surprise:

expect(selection).to.have.length(2);

The second, however, was explicitly stated in the documentation as a workaround:

expect(selection).to.be.of.length(2);

This also doesn't work. The way I'm doing it now is pretty much as @nackjicholson has stated:

expect(selection.length).to.eq(2);

This is the only way I've gotten it to work. I'm sure the other ways expressed above work also, but I'm not interested in those syntaxes.

BTW @jfirebaugh, I can confirm that this workaround does, in fact, NOT work! I would love it if it did :)

@glittershark

This comment has been minimized.

Show comment
Hide comment
@glittershark

glittershark Apr 29, 2014

👍 more descriptive error messages than "expected 2 to equal 1" would be very nice.

glittershark commented Apr 29, 2014

👍 more descriptive error messages than "expected 2 to equal 1" would be very nice.

@gumaflux

This comment has been minimized.

Show comment
Hide comment
@gumaflux

gumaflux commented Apr 30, 2014

@jedmao great thanks

@jedmao

This comment has been minimized.

Show comment
Hide comment
@jedmao

jedmao Apr 30, 2014

@gumaflux my co-worker had success with the following syntax as well:

expect(selection.length).to.be(2);

jedmao commented Apr 30, 2014

@gumaflux my co-worker had success with the following syntax as well:

expect(selection.length).to.be(2);
@jfirebaugh

This comment has been minimized.

Show comment
Hide comment
@jfirebaugh

jfirebaugh Oct 11, 2014

Member

Fixed by #47.

Member

jfirebaugh commented Oct 11, 2014

Fixed by #47.

@jfirebaugh jfirebaugh closed this Oct 11, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment