JavaScript Return value for asynchronous callback (in unit test) return value asynchronous method javascript,return value asynchronous function,return

I am attempting to do jasmine-node unit testing on my node.js project. I need to get an array of file paths and then pass that array to the unit test. However, since this is asynchronous, I have to use a callback, and I can't return the array. I can't figure out how to send the retrieved array to the unit test.

Here's my code:

module.exports = {
    results: [],
    walk: function(){
        var nodeDir = require( "node-dir" );
        nodeDir.files( __dirname + "/public/img", function( err, files ){
            if ( err ){ throw err; }    
            getData( files );
        } );  
    },
    getData: function( files ){
        console.log( files );
        results = files;
    }
};

and here's my unit test:

var gallery = require( "./server" );

describe( "Gallery", function() {
    var picArray = [
        "/gallery/public/img/dir1/lizard-248705_1280.jpg",
        "/gallery/public/img/dir1/loch-ness-151851_1280.png",
        "/gallery/public/img/dir1/sand-lizard-63185_1280.jpg",
        "/gallery/public/img/dir1/stegosaurus-24752_1280.png"];

    it( "walks the images directory", function(){
        expect(gallery.walk()).toEqual(picArray);
    });
});
Answer:1

I need to add multiple attribute to input type file but I don't know how to do it. Below My code: var input = document.createElement("input"); input.type = "file"; input.id = "files" + af; input....

I need to add multiple attribute to input type file but I don't know how to do it. Below My code: var input = document.createElement("input"); input.type = "file"; input.id = "files" + af; input....

After long time searching here around I can't find a solution to this problem, loading Datatables via Ajax GET is well documented but how can I use directly a JSON response after an Ajax POST? This ...

After long time searching here around I can't find a solution to this problem, loading Datatables via Ajax GET is well documented but how can I use directly a JSON response after an Ajax POST? This ...

  1. load datatables from json
  2. load datatables from ajax
  3. datatables load from csv
  4. datatables load from array
  5. datatables load from json string
  6. datatables load from json file
  7. datatables load from api
  8. datatables load from server
  9. datatables load from object
  10. datatables js onload
  11. datatables load from table
  12. load datatables with filter
  13. datatables load from json
  14. datatables load data from ajax
  15. datatables load data from json
  16. datatables load data from array
  17. datatables load data from object
  18. datatables load data from variable
  19. datatables load data from server
  20. datatables load data from json file

I have a video the being played. How can I call a function 5 seconds before the end of the video? I thought to put a timer when I start the video, the problem is that the user can control the video, ...

I have a video the being played. How can I call a function 5 seconds before the end of the video? I thought to put a timer when I start the video, the problem is that the user can control the video, ...

I want to check if a server is reachable with a JavaScript function. By reachable, I mean, if the server answers, I don't care which HTTP status code, it's reachable. Stackoverflow/Google helped me ...

I want to check if a server is reachable with a JavaScript function. By reachable, I mean, if the server answers, I don't care which HTTP status code, it's reachable. Stackoverflow/Google helped me ...

  1. online check deposit resource center