Finally got my code tested while being able to load it in the browser. I have a couple more questions!

Finally got my code tested while being able to load it in the browser. I have a couple more questions!
0.0 0

#1
  1. Since requireing is not an issue anymore, I felt that it’s a good idea to separate classes from the main.js file into their own files (Foo.js and Bar.js). is this a good idea?

  2. How do I name the test files? (For now, I just named them Foo.test.js and Bar.test.js)

  3. Another naming question: How do I name the source and the transpiled scripts? Currently, I just ran browserify main.js -o app.js then linked app.js on my index.html

  4. class Foo has an active method that listens for click events. How do I test this?

  5. class Foo takes HTML(jQuery) elements as constructor parameters. What should I pass when testing Foo?

  6. Last slightly unrelated question: I have a vendor folder on my repository that contains external stuff (bootstrap, jquery, font-awesome etc.). How do I create a branch named local (contains vendor folder) and production (uses CDN) without manually copy pasting each components?

Thanks! <3


#2

Since requireing is not an issue anymore, I felt that it’s a good idea to separate classes from the main.js file into their own files (Foo.js and Bar.js). is this a good idea?

Definitely a good idea
Here’s a nice post that explains why:

How do I name the test files? (For now, I just named them Foo.test.js and Bar.test.js)

Another naming question: How do I name the source and the transpiled scripts? Currently, I just ran browserify main.js -o app.js then linked app.js on my index.html

The convention is to put test files in test directory that mirrors the structure of tested files. Each file should end with .test.js

Alternatively. check your favorite open source project on github for inspiration. They’ll definitely have tests there.

class Foo has an active method that listens for click events. How do I test this?

class Foo takes HTML(jQuery) elements as constructor parameters. What should I pass when testing Foo?

https://www.npmjs.com/package/mocha-jsdom

Last slightly unrelated question: I have a vendor folder on my repository that contains external stuff (bootstrap, jquery, font-awesome etc.). How do I create a branch named local (contains vendor folder) and production (uses CDN) without manually copy pasting each components?

Prepare two build configs, one for production and one for development.
http://beletsky.net/2015/01/configuring-front-end-applications.html


#3

You are amazing. Thanks for the help! :sunny: