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

plan and Lab.assertions not working #693

Closed
skaterdav85 opened this issue Mar 18, 2017 · 9 comments
Closed

plan and Lab.assertions not working #693

skaterdav85 opened this issue Mar 18, 2017 · 9 comments
Assignees
Labels
Milestone

Comments

@skaterdav85
Copy link

@skaterdav85 skaterdav85 commented Mar 18, 2017

I'm trying to use the "plan" feature but I get an error. Here is my test:

const Code = require('code');
const Lab = require('lab');
const lab = exports.lab = Lab.script();

lab.experiment('math', () => {
  lab.test('returns true when 1 + 1 equals 2', { plan: 1 }, (done) => {
    Code.expect(1 + 1).to.equal(2);
    done();
  });
});

and then I run "lab". I get this:

Test script errors:

Expected 1 assertions, but no assertion library found
      at lab.test (/Users/david/Sites/testing-with-lab/test/example-test.js:17:5)
      at runCallback (timers.js:651:20)
      at tryOnImmediate (timers.js:624:5)
      at processImmediate [as _immediateCallback] (timers.js:596:5)

Do I need to tell the lab variable about which assertion library I am using?

I also noticed Lab.assertions.expect doesn't work either.

const Code = require('code');
const Lab = require('lab');
const lab = exports.lab = Lab.script();
const expect = Lab.assertions.expect;

lab.experiment('math', () => {
  lab.test('returns true when 1 + 1 equals 2', (done) => {
    Code.expect(1 + 1).to.equal(2);
    done();
  });
});

I get TypeError: Cannot read property 'expect' of null. Clearly I am missing something. I'm just not sure what it is. Thanks.

@skaterdav85 skaterdav85 changed the title How do I use the "plan" feature? plan and Lab.assertions not working Mar 18, 2017
@cjihrig

This comment has been minimized.

Copy link
Contributor

@cjihrig cjihrig commented Mar 18, 2017

Are you passing -a code from the command line?

@skaterdav85

This comment has been minimized.

Copy link
Author

@skaterdav85 skaterdav85 commented Mar 18, 2017

@cjihrig yes I've tried that. I still get this error: Expected 1 assertions, but no assertion library found

@geek

This comment has been minimized.

Copy link
Member

@geek geek commented Mar 28, 2017

@skaterdav85 what version of lab are you running? I tried to reproduce on the latest version of lab and code and didn't encounter the issue with your code.

lab plan.js -a code


  .

1 tests complete
Test duration: 8 ms
Assertions count: 1 (verbosity: 1.00)
No global variable leaks detected
@geek geek self-assigned this Mar 29, 2017
@skaterdav85

This comment has been minimized.

Copy link
Author

@skaterdav85 skaterdav85 commented Mar 30, 2017

@geek I am running the following:

lab: 13.0.1
node: 7.5.0
npm: 4.1.2
nvm: 0.31.0
@geek

This comment has been minimized.

Copy link
Member

@geek geek commented Mar 30, 2017

@skaterdav85 thanks for the update. What version of code are you using. I tried again and still no luck...

lab: 13.0.1
node: 7.5.0
code: 4.0.0
$ cat plan.js
const Code = require('code');
const Lab = require('lab');
const lab = exports.lab = Lab.script();

lab.experiment('math', () => {
  lab.test('returns true when 1 + 1 equals 2', { plan: 1 }, (done) => {
    Code.expect(1 + 1).to.equal(2);
    done();
  });
});

$ npm i lab@13.0.1

$ npm i code@4.0.0

$ ./node_modules/.bin/lab plan.js -a code


  .

1 tests complete
Test duration: 9 ms
Assertions count: 1 (verbosity: 1.00)
No global variable leaks detected
@skaterdav85

This comment has been minimized.

Copy link
Author

@skaterdav85 skaterdav85 commented Mar 30, 2017

Well I got it working after reinstalling a few weeks later, so I'm not sure what the problem was. Different error now though. When I run it with ./node_modules/.bin/lab plan.js, it works. When I install lab globally like in the README and run lab plan.js, it says Cannot find module 'code'. Does that mean I have to install code globally too?

@Marsup

This comment has been minimized.

Copy link
Member

@Marsup Marsup commented Mar 30, 2017

You shouldn't install those things globally anyway :trollface:

@skaterdav85

This comment has been minimized.

Copy link
Author

@skaterdav85 skaterdav85 commented Mar 30, 2017

@Marsup Ah ok. Should the README be updated to remove that? :)

@Marsup

This comment has been minimized.

Copy link
Member

@Marsup Marsup commented Mar 30, 2017

I would say so yes, it's a very bad advice, and when you start with node you don't know any better.

@geek geek added the documentation label Apr 4, 2017
@geek geek added this to the 13.0.2 milestone Apr 4, 2017
@geek geek closed this in 5bfeb49 Apr 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.