Hi Mikkel

This is a good work around. I think you might be right---I may not have
been thinking clearly about jquery.

Thanks, Evan

On Mon, Apr 30, 2018 at 3:54 PM, Mikkel Wilson <[email protected]> wrote:

> So, this is a server-side javascript environment. jQuery is more suited to
> a client-side environment (in a browser, not on a server). I think you're
> trying to use jQuery to make a request to a /metadata endpoint on a server
> to get some JSON. I'd suggest you use the 'request' package instead.
>
> First, install the package:
>
> npm install request --save
>
>
> Then, you can use it in your misc.js file:
>
> const request = require('request');
>
>
> Finally, you can replace your $.ajax call with request like this:
>
> request(Misc.server+'/metadata', function(err, response, body){
>   if(err) {
>     console.log(err);
>     return;
>   }
>   console.log(body);
> }
>
> HTH,
> Mikkel
> https://www.oblivious.io/ <https://www.oblivious.io/?r=googlenodejs>
>
> On Sunday, April 29, 2018 at 2:16:34 PM UTC-7, EB wrote:
>>
>> I'm confused how to export jQuery correctly in order to test several
>> functions with mocha and the assertion library chai. Hopefully this is a
>> beginner's error...
>>
>> Here is the code I am testing, with the branch `add_tests`:
>>
>> https://github.com/mskilab/gGnome.js/tree/add_tests
>>
>> I'm having trouble with the functions in
>> https://github.com/mskilab/gGnome.js/blob/master/js/misc.js
>>
>> with the tests here:
>> https://github.com/mskilab/gGnome.js/blob/add_tests/test/miscTest.js
>>
>>
>> So, in order to export jQuery, I include the following line:
>>
>> https://github.com/mskilab/gGnome.js/blob/add_tests/js/misc.js#L2
>>
>>     const $ = require('jquery');
>>
>> However, I'm still getting errors when I try to use the functions in
>> `miscTest.js`, whereby I'm running `mocha` or `npm test`, I get a TypeError:
>>
>>     TypeError: $.ajax is not a function
>>
>> This is from trying to run
>>
>>     console.log(Misc.metadata);
>>
>> within `misc.js`
>>
>> How do I correctly export jQuery so it's recognized?
>>
>> --
> Job board: http://jobs.nodejs.org/
> New group rules: https://gist.github.com/othiym23/9886289#file-
> moderation-policy-md
> Old group rules: https://github.com/joyent/node/wiki/Mailing-List-
> Posting-Guidelines
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/nodejs/76053819-61e2-4878-9f7b-2c44af693e31%40googlegroups.com
> <https://groups.google.com/d/msgid/nodejs/76053819-61e2-4878-9f7b-2c44af693e31%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/CABFhwYNFwiOEOvm1-WpYNSrQ2JfmxYmNQZGF2G%3DhDvUSJTqSAQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to