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

how to access Promise in test code ? #180

Open
welelay opened this issue Jun 2, 2016 · 6 comments
Open

how to access Promise in test code ? #180

welelay opened this issue Jun 2, 2016 · 6 comments

Comments

@welelay
Copy link

welelay commented Jun 2, 2016

I'd like to test a rest api with gagarin.
I figured I could use the 'http' module of node.js.
No big deal : require('http'); at begining of test files.
But then, I have to return a promise in my test, like

    it("....", function() {
        return client
            .execute(function() {
                return computedEnpoint();
            }).then(function(url) {

               return new Promise(function(reject, resolve){
                       http.get(url, function(res){
                            resolve("How cool?");
                       });
               });

            });
     });

It fails with Promise is undefined.
I can't find a way to grab promise from meteor, or with a require.

@welelay
Copy link
Author

welelay commented Jun 2, 2016

I can't do it from client using $.get because the endpoint redirects to another domain without CORS headers.

@apendua
Copy link
Member

apendua commented Jun 2, 2016

@welelay Have you tried es6-promise npm package?

@welelay
Copy link
Author

welelay commented Jun 3, 2016

Yes, with no success:

var p = require("es6-promise");

on top of the test script fails with

Error: Cannot find module 'es6-promise'
  at Function.Module._resolveFilename (module.js:338:15)
  at Function.Module._load (module.js:280:25)
  at Module.require (module.js:364:17)
  at require (module.js:380:17)
  at Object.<anonymous> (/app/tests/gagarin/api_test.js:6:9)

@apendua
Copy link
Member

apendua commented Jun 3, 2016

@welelay Does installing es6-promise globally help?

@welelay
Copy link
Author

welelay commented Jun 3, 2016

nope

@apendua
Copy link
Member

apendua commented Jun 3, 2016

@welelay Can you please read the discussion at #141 and see if it's helpful.

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