I have the following ArrayController:
Lead.Controllers.Leads = Ember.ArrayController.extend
init: ->
content: Ember.A()
#view = Ember.View.create
controller: #
templateName: 'app/templates/leads/list'
#view.appendTo $('#leads')
addLead: (data) ->
lead = Lead.Lead.create()
lead.setProperties JSON.parse data
console.log lead.get 'company'
debugger
#pushObject lead
console.log #get('length')
The problem is after I call push object, the length is still 0. I really cannot see what I am doing wrong.
Can anyone see what I am doing wrong? The only thing I can think of is that the Content is set to an empty array via Ember.A().
I have no idea what else it could be.
I'm not quite sure where your problem is since I a) don't really know or use CoffeeScript and b) there's no jsFiddle or working example. But if I'm reading this correctly your trying to do the following: See this jsFiddle which works as expected. Hope that points you in the right direction.
It's a Coffee Script syntax error.
There are two solutions (depending on what you want to implement).
The second example will use the same array for every instance of the controller.
Also, I'd recommend calling #_super() when overriding the init method, otherwise you might get some unexpected results with certain classes.
Ember.ArrayController.extend
init: ->
#_super()
#set 'content', Ember.A()
# content
Ember.ArrayController.extend
content: Ember.A()
init: ->
#_super()
# content
Related
I love testing-library, have used it a lot in a React project, and I'm trying to use it in an Angular project now - but I've always struggled with the enormous error output, including the HTML text of the render. Not only is this not usually helpful (I couldn't find an element, here's the HTML where it isn't); but it gets truncated, often before the interesting line if you're running in debug mode.
I simply added it as a library alongside the standard Angular Karma+Jasmine setup.
I'm sure you could say the components I'm testing are too large if the HTML output causes my console window to spool for ages, but I have a lot of integration tests in Protractor, and they are SO SLOW :(.
I would say the best solution would be to use the configure method and pass a custom function for getElementError which does what you want.
You can read about configuration here: https://testing-library.com/docs/dom-testing-library/api-configuration
An example of this might look like:
configure({
getElementError: (message: string, container) => {
const error = new Error(message);
error.name = 'TestingLibraryElementError';
error.stack = null;
return error;
},
});
You can then put this in any single test file or use Jest's setupFiles or setupFilesAfterEnv config options to have it run globally.
I am assuming you running jest with rtl in your project.
I personally wouldn't turn it off as it's there to help us, but everyone has a way so if you have your reasons, then fair enough.
1. If you want to disable errors for a specific test, you can mock the console.error.
it('disable error example', () => {
const errorObject = console.error; //store the state of the object
console.error = jest.fn(); // mock the object
// code
//assertion (expect)
console.error = errorObject; // assign it back so you can use it in the next test
});
2. If you want to silence it for all the test, you could use the jest --silent CLI option. Check the docs
The above might even disable the DOM printing that is done by rtl, I am not sure as I haven't tried this, but if you look at the docs I linked, it says
"Prevent tests from printing messages through the console."
Now you almost certainly have everything disabled except the DOM recommendations if the above doesn't work. On that case you might look into react-testing-library's source code and find out what is used for those print statements. Is it a console.log? is it a console.warn? When you got that, just mock it out like option 1 above.
UPDATE
After some digging, I found out that all testing-library DOM printing is built on prettyDOM();
While prettyDOM() can't be disabled you can limit the number of lines to 0, and that would just give you the error message and three dots ... below the message.
Here is an example printout, I messed around with:
TestingLibraryElementError: Unable to find an element with the text: Hello ther. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.
...
All you need to do is to pass in an environment variable before executing your test suite, so for example with an npm script it would look like:
DEBUG_PRINT_LIMIT=0 npm run test
Here is the doc
UPDATE 2:
As per the OP's FR on github this can also be achieved without injecting in a global variable to limit the PrettyDOM line output (in case if it's used elsewhere). The getElementError config option need to be changed:
dom-testing-library/src/config.js
// called when getBy* queries fail. (message, container) => Error
getElementError(message, container) {
const error = new Error(
[message, prettyDOM(container)].filter(Boolean).join('\n\n'),
)
error.name = 'TestingLibraryElementError'
return error
},
The callstack can also be removed
You can change how the message is built by setting the DOM testing library message building function with config. In my Angular project I added this to test.js:
configure({
getElementError: (message: string, container) => {
const error = new Error(message);
error.name = 'TestingLibraryElementError';
error.stack = null;
return error;
},
});
This was answered here: https://github.com/testing-library/dom-testing-library/issues/773 by https://github.com/wyze.
I use webread() to download data from a website's API.
Everything works - except that each function call is way too slow for my needs.
According to the profiler a large portion of the processing time is spent in a function called HTTPConnector.getConnectionContentType().
But it doesn't even seem to matter whether or not I'm using weboptions() for specifying the content type explicitly -
HTTPConnector.getConnectionContentType() seems to get called by webread() no matter what.
Here's a code snippet to show which options I've specified for the call to webread():
url = %someURL
options = weboptions('MediaType', 'application/json', ...
'ContentType', 'json' , ...
'KeyName', 'Authorization' , ...
'KeyValue', ['Bearer ', api.token]);
response = webread(url, options);
Am I doing something wrong?
Or Is there any way to speed this up?
Checking the type is not what slows down your code. The getConnectionContentType function is the first function which requires the content of the response and thus triggers the download of the data. If you would bypass it, the next function which looks into the content would show up in your profile.
For reference, open the HTTPConnector.m and read the comment for getConnectionContentType
I am trying to click on a menu dropdown. The dropdown appears when the mouse pointer is on a menu element. The workaround can be by clicking on the menu element aslo but that sometimes is giving error due to wait time being large or small depending on the speed of site.Thus, I want to use ActionChains move_to_element for this. But it is not working no errors nothing but not working.
my $driver = Selenium::Chrome->new(binary=>"D:\\chromedriver_win32\\chromedriver.exe");
my $action_chains = Selenium::ActionChains->new(driver => $driver);
$elem = $driver->find_element(".//*[\#id='navl']/li[3]/a");
$action_chains->move_to_element($elem);
$driver->pause(5000);
$driver->find_element_by_xpath(".//*[\#id='navl']/li[3]/ul/li[1]/a")->click;
$driver->pause(50000);
$driver->shutdown_binary;
I am not sure if it is of any help - there are many questions about Selenium actions and action chains and many suggestions - I struggled with a similar problem, using Python Selenium bindings though.
First of all in the code above, it could be that there is no final perform() method called after move_to_element
Secondly - and that thing was my own problem and the source of lots of bafflement on my side - i discovered that in my case, after a single perform(), i couldn't reuse the same ActionChains object - there was no error or complaint, but something was not happening right. After I created a new ActionChains object, the subsequent new chain of actions and the final perform() worked as expected.
I'm very new to CoffeScript and want to edit some code that I found. Right now, it runs this function right when the DOM is loaded:
jQuery ->
$('#s3-uploader').S3Uploader
How can I rewrite it such that it only runs after the page is loaded? I need to wait so I can get the correct instance variables:
(on page load) ->
$('#s3-uploader').S3Uploader
additional_data: {project_id: #project.id, step_id: #step.id, user_id: current_user.id}
This is quite an old question, and no doubt you have found a solution already. But for the benefit of anyone coming here from Google....
It is also not 100% clear from your question, but you appear to be using a framework such as Ruby on Rails.
If so, then the correct answer of course is that you should not be accessing instance variables from Coffeescript. Coffeescript files in the asset pipeline are compiled during deployment, and have no knowledge of the controller or instance variables.
The correct way is to assign these variables to data attributes in the DOM, and then reference the data attributes.
#view.html.erb
<div id="uploader" data-project_id="<%= #project.id %>" ></div>
#script.coffee.js
(on page load) ->
$('#s3-uploader').S3Uploader
additional_data: {project_id: $('#uploader').data('project_id') .... }
For rails, this worked for me when all the other answers here did not:
$(document).on "turbolinks:load", ->
You're looking for $(document).ready event handler.
$(document).ready ->
$('#s3-uploader').S3Uploader
checkVariable = ->
if variableLoaded == true
# here is your next action
else
return
setTimeout 'checkVariable()', 1000
I have a parent model that has many child models, for example:
App.Blog = Ember.Object.extend({})
App.Comment = Ember.Object.extend({})
Then I have a view for the Blog:
window.App.BlogView = Ember.View.extend
templateName: 'app_templates_blog'
Now, when I initially retrieve a Blog via my REST API, it contains the first 10 Comments or so. Those are instantiated like this:
window.App.Blog.reopenClass
create: (obj) ->
Object.tap #_super(obj), (result) =>
if result.comments
result.comments = result.comments.map (p) => App.Comment.create(p)
I display by blog by calling BlogView.set('blog', blogInstance) and everything is displaying perfectly.
However!
I am implementing an infinite scroll, so when the end user gets to the bottom of the comments, I want to load more. I do this via REST, but I can't for the life of me get them to display by appending them.
This is what my morePosts() method looks like in BlogView:
moreComments: () ->
blog = #get('blog')
jQuery.getJSON "/blogs/#{blog.get('id')}/comments", (result) =>
comments = blog.get('comments')
result.each (c) => comments.push(App.Comment.create(c))
blog.set('comments', comments)
this.set('blog', blog)
However, this never seems to add the new comments. What am I doing wrong here?
To properly support Ember's bindings and observers, you need to use KVO aware getters and setters. Just as you use get and set for standard properties, you also have to use special methods for Arrays. In this case, you'd use pushObject. You can see a full list of the functions implemented here: https://github.com/emberjs/ember.js/blob/master/packages/ember-runtime/lib/mixins/mutable_array.js.