anticoders / gagarin

Another testing framework for your meteor apps.
gagarin.meteor.com
MIT License
150 stars 21 forks source link

how to access Promise in test code ? #180

Open welelay opened 8 years ago

welelay commented 8 years ago

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 commented 8 years ago

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

apendua commented 8 years ago

@welelay Have you tried es6-promise npm package?

welelay commented 8 years ago

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 commented 8 years ago

@welelay Does installing es6-promise globally help?

welelay commented 8 years ago

nope

apendua commented 8 years ago

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