coffeescript

How to expose javascript objects for unit testing without polluting the global namespace

久未见 提交于 2019-12-14 00:32:07
问题 I have a javascript autocomplete plugin that uses the following classes (written in coffeescript): Query, Suggestion, SuggestionCollection, and Autocomplete. Each of these classes has an associated spec written in Jasmine. The plugin is defined within a module, e.g.: (function(){ // plugin... }).call(this); This prevents the classes from polluting the global namespace, but also hides them from any tests (specs with jasmine, or unit-tests with something like q-unit). What is the best way to

node.js synchronous mysql query [closed]

巧了我就是萌 提交于 2019-12-13 22:24:37
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . How can I use mysql synchronously in node.js ? I want to execute query and render properly rendered form with datas from database, like: userData = db.query "SELECT * FROM users WHERE id=1" form.bind(userData)

Dynamic async parallel task

孤街醉人 提交于 2019-12-13 21:24:32
问题 Context: I fetched some "users". I want to know more about these specific users before returning the response, so I fetch detailed info for all users and add that to a result...then I return the result after all requests have finished. I'm having trouble using the parallel call: async = require 'async' # Assume I don't know how many users are here. Test data. users = [ name: 'user1' , name: 'user2' ] # Fake add some extra data to the user. fetchUser = (name, cb) -> setTimeout (-> user = name:

Coffeescript HTTP client

烂漫一生 提交于 2019-12-13 21:16:10
问题 I am running server.coffee from this page: https://github.com/xenph/foaas From the command line, you can do: curl http://localhost:5000/off/Name1/Name2 !@#$ off, Name1. - Name2 But I'm using the code from this page: http://coffeescriptcookbook.com/chapters/networking/basic-http-client http = require 'http' http.get { host: 'http://localhost:5000/off/Name1/Name2' }, (res) -> data = '' res.on 'data', (chunk) -> data += chunk.toString() res.on 'end', () -> console.log data The error I get is:

How do I create a named function expressions in CoffeeScript?

人盡茶涼 提交于 2019-12-13 17:23:41
问题 How do I create a named function expressions in CoffeeScript like the examples below? var a = function b (param1) {} or return function link (scope) {} 回答1: Coffeescript doesn't support the latter (named functions), but the former can be achieved with a = (param1) -> console.log param1 回答2: I may be a bit late to the party, but I just realised that you actually create named functions when using the class keyword. Example: class myFunction # The functions actual code is wrapped in the

Error callback always fired, even when it is successful

荒凉一梦 提交于 2019-12-13 17:05:32
问题 There should be a glitch in my syntax, or something I haven't understood, but when I am doing a save method on my model. The error callback is called whatever the outcome of the method. @new_activity = new Activity() @new_activity.save know: $('input#know').val() learn: $('input#learn').val() success: -> console.log 'success' error: -> console.log 'error' In my case, since I do not really know whether the new_activity has effectively passed the validation, I have to do an ugly trick to add

Mocha tests for asynchronous functions

时光怂恿深爱的人放手 提交于 2019-12-13 16:25:32
问题 I'm writing a node wrapper to interact with an external api and am having a difficult time testing the asynchronous createJob method. Below is the test case code: api_key = "test_0dc8d51e0acffcb1880e0f19c79b2f5b0cc" lob = require('../src/lob')(api_key) should = require("should") chai = require("chai") data = name: "test name" to: "Bob" from: "Alice" object1: "foo" object2: "bar" describe "Job", -> @timeout(50000) describe "create", -> it "should create a job with address_id", (done) -> lob

Pass Gulp sources to gulp-coffee, gulp-concat, and webpack-stream

筅森魡賤 提交于 2019-12-13 16:20:49
问题 I have the code: var gulp = require('gulp'); var webpack = require('webpack-stream'); var coffee = require('gulp-coffee'); var concat = require('gulp-concat'); gulp.task('webpack', function() { gulp.src('*/lib/*.coffee', { base: '.' }) .pipe(coffee({ bare: true })) .pipe(concat('app.js')) .pipe(webpack()) .pipe(gulp.dest('.')); }); However, it doesn't work, when it reaches webpack() . How can I make it so that the content passed from concat() to webpack() works successfully? I also assume

Marionette CompositeView renders itself for each Model in Collection instead of ItemView (Marionette Rails)

假装没事ソ 提交于 2019-12-13 15:10:59
问题 Basically, I'm trying to render a CompositeView as a simple four-column list with a table header, where each model in a collection is rendered into a and appended to the . I'm following an example of Derick's quite closely with only a little variation, but unfortunately have gotten some pretty strange results. Instead of rendering each itemView, the view instead references itself and re-renders for each item in the collection, producing a new table and table head. Before that, It was

Javascript: ReferenceError: MyClass is not defined

牧云@^-^@ 提交于 2019-12-13 14:13:26
问题 This is very basic. I try to instantiate a Class defined in an external .js file embedded. The code of the .js is simply this. (function() { var MyClass; MyClass = (function() { function MyClass() {} MyClass.prototype.name = function(name) {}; return MyClass; })(); }).call(this); And the HTML is this <!DOCTYPE html> <html> <head> <title>Sample Page</title> <script src="file.js" type="text/javascript"></script> </head> <body> </body> </html> If I try on the console to instantiate the class but