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

Jasmine matcher couldn't be called from after() #307

Closed
naruoga opened this issue Mar 29, 2016 · 5 comments
Closed

Jasmine matcher couldn't be called from after() #307

naruoga opened this issue Mar 29, 2016 · 5 comments

Comments

@naruoga
Copy link

naruoga commented Mar 29, 2016

With running a following test code,

const frisby = require('frisby');

frisby.create("sample")
  .get("url")
  .after(function(err, res, body) {
      expect(res.statusCode).not().toEqual(500)
  })
  .toss()

I got:

Failures:

  1) Frisby Test: sample 
        [ GET url ]
   Message:
     TypeError: expect(...).not is not a function
   Stacktrace:
     TypeError: expect(...).not is not a function
    at Frisby.<anonymous> (.../spec/foo_spec.js:7:30)
    at Frisby.<anonymous> (.../node_modules/frisby/lib/frisby.js:940:8)
    at null.<anonymous> (.../node_modules/frisby/lib/frisby.js:1112:18)
    at Timer.listOnTimeout (timers.js:92:15)

I thought I made some mistake... Could you point me out?

@cpanato
Copy link

cpanato commented Mar 29, 2016

you dont need to match the status code in the after function there is a helper to make that easier:

frisby.create('api_ad_call_v1: REQUEST 1')
  .get(url)
  .expectStatus(200)
  .toss();

however if you want to use in your way you need add a ; in the end of your expect to make it work

frisby.create('api_ad_call_v1: REQUEST 1')
  .get(url)
  .after(function(err, res, body) {
      expect(res.statusCode).not.toEqual(500);
  })
  .toss();

@naruoga
Copy link
Author

naruoga commented Mar 29, 2016

Thanks @ctadeu to mention tailing semicolon. JavaScript is not my mother tongue...

Anyway, I still have a same error with semicolon.

I will be happy if I could use expectStatus(), but my target API return several status codes randomly (basically "200", but in some case returns "20x"), and I thought I need to use "expect() inside "after()."
Or, can I use expectStatus() or anything else Frisby-style matcher to expect "multiple" status codes?

@cpanato
Copy link

cpanato commented Mar 29, 2016

I made the same example here and it works. How are you running your spec?

@naruoga
Copy link
Author

naruoga commented Mar 29, 2016

Hmm, it seems as an environmental issue I guess, but I couldn't expect the reason why.
My environment is:

  • OS X El Capitan
  • node 4.2.1 (brew installed)
  • frisby 0.8.5 (npm installed, locally)
  • jasmine-node 1.14.3 (npm installed, globally)

And I run the script named sample_spec.js by launching jasmine-node command:

$ jasmine-node --verbose sample_spec.js

Frisby Test: sample - 74 ms

        [ GET url ] - 73 ms

Failures:

  1) Frisby Test: sample 
        [ GET url ]
   Message:
     TypeError: expect(...).not is not a function
   Stacktrace:
     TypeError: expect(...).not is not a function
    at Frisby.<anonymous> (.../spec/sample_spec.js:6:25)
    at Frisby.<anonymous> (...node_modules/frisby/lib/frisby.js:940:8)
    at null.<anonymous> (.../node_modules/frisby/lib/frisby.js:1112:18)
    at Timer.listOnTimeout (timers.js:92:15)

Finished in 0.079 seconds
1 test, 1 assertion, 1 failure, 0 skipped

Any comment?

@naruoga
Copy link
Author

naruoga commented Apr 1, 2016

Finally I found my mistake,

const frisby = require('frisby');

frisby.create("sample")
  .get("url")
  .after(function(err, res, body) {
      expect(res.statusCode).not().toEqual(500)
  })
  .toss()

the code above, .not() should be not, not a method chain.

Sorry for annoyance, and now I have a code which works well as I expected.

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

2 participants