Skip to content
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

.toBeGreaterThan(-1) #58

Closed
JeffreyArts opened this issue Dec 20, 2015 · 2 comments
Closed

.toBeGreaterThan(-1) #58

JeffreyArts opened this issue Dec 20, 2015 · 2 comments

Comments

@JeffreyArts
Copy link

I am having issues with setting a cookie, and test if the cookie is set properly.
When I set a Cookie 'foo' with the value 'bar' and I check the test if it is created succesfully by the following condition:

document.cookie.indexOf('foo=bar')

It returns 0, since the cookie will be added at the beginning of the string. I see that that is correct by the following statement:

expect(document.cookie.indexOf('foo=bar')).toBeGreaterThan(0);

This ofcourse will throw an error (Error: Expected 0 to be greater than 0). Which is ok, but whenever I try to update this test, like so:

expect(document.cookie.indexOf('foo=bar')).toBeGreaterThan(-1);

It gives me a timeout error (Error: timeout of 2000ms exceeded). Could you please explain me, why that is?

@mjackson
Copy link
Owner

This almost certainly has nothing to do with expect since the call to toBeGreaterThan will run synchronously. It's probably something with your mocha setup.

@rstacruz
Copy link
Collaborator

What likely happened is that the expectation passed, therefore making the test continue on:

it('doesnt work', function (next) {
  expect(document.cookie.indexOf('foo=bar')).toBeGreaterThan(0)
  // (!) error raised, test aborted
})


it('works', function (next) {
  expect(document.cookie.indexOf('foo=bar')).toBeGreaterThan(-1)
  // expectation passed, everything is peachy, but since no one is
  // calling `next()` mocha is left hanging
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants