Git Product home page Git Product logo

Comments (9)

btk avatar btk commented on August 28, 2024 1

@gatukgl yes I think you should initilize your own assets.js file before starting your test. Like you can have a test asset folder;

test-assets/
 - asset1.png
 - asset2.png
 - ...

Thank you can initilize the node index test-assets/ assets.js

Then you can use the assets.js file that you generated for your tests.

from pre-require.

gatukgl avatar gatukgl commented on August 28, 2024 1

I just have an idea to separate both search() and format() in index.js to be real functions (not just a plain text) so we can easily write unit tests. Would you mind if I open a new issue to refactor that two? :D

So it will looks like below.

   // index.js
    ...

    let assetsFileContent = `// import this file for static assets
    let Obj = {
      ${slugArray.join(', ')},
      search: ${searchFile},
      format: ${searchFileFormat}
    }
    export default Obj;
    `;

   ...

const searchFile = function(key) {
  if(this.hasOwnProperty(key)) {
    return this[key];
  } else {
    return -1;
  }
}

const searchFileFormat = function(extension) {
  let filteredArray = this.filter(assetSlug => (assetSlug.includes("-"+extention)));
    if(filteredArray.length){
       return filteredArray;
    } else {
       return -1;
    }
}

from pre-require.

gatukgl avatar gatukgl commented on August 28, 2024

I'm working on it. 🎉

from pre-require.

btk avatar btk commented on August 28, 2024

@gatukgl that's great, if you have any question with the usage cases you can ask in this issue.

from pre-require.

gatukgl avatar gatukgl commented on August 28, 2024

@btk I wonder, to test .format and .search function. Is that ok to test on assets.js file?

from pre-require.

btk avatar btk commented on August 28, 2024

@gatukgl yeah, that is actually really smart!

How do you plan to get them functions into text so the generated file will be as intended? Your current code, (I'm not sure but) ${searchFile} won't work? Maybe you can use something like function.prototype.toString()

See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString

If you can manage the "real" functions to be printed in the assets.js as intended, I would love to see your pr. Thank you.

from pre-require.

gatukgl avatar gatukgl commented on August 28, 2024

Great!! I’ll try :) Thank you.

from pre-require.

gatukgl avatar gatukgl commented on August 28, 2024

@btk I've already opened PR to test .search() and I'm just curious, for the .filter() in .format(), does it work with an object?

from pre-require.

btk avatar btk commented on August 28, 2024

Handled by #31

We might have a new issue to list other possible test cases to be implemented in future. Thank you.

from pre-require.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.