Should source code know it's being tested? [closed] - javascript

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I have a complex codebase with tight couplings between functions and I am not able to write unit tests easily.
Should source code know about testing environment, should it know it's being tested?
To indicate it's being tested or so can be easily via global flag but I have a fear it may cause a bigger mess in the long run.

In short, no.
Your code should be written in such a fashion that it is testing-agnostic. What I mean is that it shouldn't care if it is being tested or not. Because of your 'tight couplings' I would suggest that you do your testing as manually as you can since that would give you the best litmus test of it working as expected.
Also, if your code is implemented well enough it would also be environment agnostic. Whatever environment you test in should be as close to real-world as possible.

Related

Javascript and Priority Queues in coding interviews [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
One pretty big issue I've run into with JS is that it has no in built in priority queue unlike Java or Python (heapq).
I was just wondering in an interview situation, could you propose below solution and essentially 'pretend' that JS does indeed have a native Priority Queue structure:
https://leetcode.com/problems/merge-k-sorted-lists/discuss/10528/A-java-solution-based-on-Priority-Queue
Only asking because implementing a MinHeap is pretty complicated and not sure if I'll able to do it in a high stress environment.
I think it's fair to assume you can use an npm library to make JavaScript have capabilities comparable to other languages.
Google Closure Library has some useful structures implemented in JavaScript.
You can find goog.structs.PriorityQueue here.
Facebook similarly has fbjs.
You can find their Heap implementation here.

javascript/Jquery code organisation [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'm creating a php app where almost all requests are in ajax and some Jquery effects, so some of my pages are up to 2000 lines of code, all my jquery in one big $document.ready{}, is it normal? should I be ashamed of showing this code to other developers? or is there a better way of organasing Jquery code ?
Like how many others have said, if it's maintainable and easy to read then it shouldn't be much of an issue. However, in my experiences, code that is organized into separate logical modules were MUCH easier to read and maintain than one long document.
With that being said, the typical workflow these days with tools such as browserify would be to refactor and separate the code such that each file executes a specific task for development purposes and when it is time to deploy to production, one would use a build tool to group/minify and optimize for the browser.

Best practice for including css and javascript files [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I've always wondered about including javascript libraries and a mess of stylesheets in pages that don't ever use them. It got me wondering if maybe performance would improve, however slight, if I were to include these files on an as needed basis. Is there a best practice to go by on this? Some of these javascript libraries are very large and if they're not needed, it would seem to me that they shouldn't be included.
I'd like to hear the thoughts from others on this.
I think you are talking about Asynchronous Module Definitions (AMD).
One of the more popular implementations of this is Require.js. Check it out.

Is it a bad idea to build integration tests purely with Javascript and run in the browser? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
We are experimenting with different methods of integration testing. One option we thought of was to build something purely in Javascript and run in the browser. These tests would use jQuery to navigate and fill the DOM and then run simple comparisons to return true or false.
We built something quickly to try the idea and it works well. We run the script in the console of a browser. We created several identical tests with Capybara and Selenium and our method runs just as fast.
I searched and couldn't find anyone else doing this and was wondering if there is something I'm not realizing that makes this a bad idea.
Many libraries do it: QUnit and JSUNIT are two examples
But you can use Selenium WebDriver to do a lot of it without JavaScript.

how do you model your javascript? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I'm trying to model my javascript object using visio, visio doesn't support javascript data types.
Then I start thinking, how do you desing model your javascript code?
Cheers
In the past, I've used Open Source tools like Dia and just fudged the data types where needed...
It's enough to get the idea across, but you're definitely not going to get anything even close to code generation from it.
I prefer Object Oriented design - even for JavaScript - so I suggest Rational Rose. I like some of the features of OO (e.g. encapsulation and abstraction) and like to add some discipline to a potentially undisciplined environment - especially when working with developers new to JavaScript. Rose meets my needs.

Categories

Resources